From 23bf71d06a5ae290e101130b6fe675cff380f9ca Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 24 Mar 2021 09:24:45 +0000 Subject: [PATCH 1/8] Intermediate commit --- include/etl/binary.h | 131 ++ include/etl/experimental/crc.h | 82 ++ include/etl/experimental/crc16.h | 82 ++ include/etl/experimental/crc16_aug_ccitt.h | 82 ++ include/etl/experimental/crc16_ccitt.h | 82 ++ include/etl/experimental/crc16_genibus.h | 82 ++ include/etl/experimental/crc16_kermit.h | 82 ++ include/etl/experimental/crc16_modbus.h | 82 ++ include/etl/experimental/crc16_usb.h | 82 ++ include/etl/experimental/crc16_x25.h | 82 ++ include/etl/experimental/crc16_xmodem.h | 87 ++ include/etl/experimental/crc32.h | 82 ++ include/etl/experimental/crc64_ecma.h | 82 ++ include/etl/experimental/crc8_ccitt.h | 83 ++ include/etl/experimental/crc8_rohc.h | 83 ++ include/etl/experimental/crc8_table16.h | 234 +++ include/etl/experimental/crc8_table256.h | 347 +++++ include/etl/experimental/crc8_table4.h | 212 +++ include/etl/experimental/crc_implementation.h | 656 +++++++++ include/etl/experimental/crc_parameters.h | 42 + include/etl/experimental/crc_table_16.h | 701 +++++++++ include/etl/experimental/crc_table_256.h | 519 +++++++ include/etl/experimental/crc_table_4.h | 698 +++++++++ .../etl/experimental/crc_table_generator.h | 712 ++++++++++ test/test_crc_table16.cpp | 1259 +++++++++++++++++ test/test_crc_table256.cpp | 1259 +++++++++++++++++ test/test_crc_table4.cpp | 1259 +++++++++++++++++ test/vs2019/etl.vcxproj | 18 + test/vs2019/etl.vcxproj.filters | 57 + 29 files changed, 9259 insertions(+) create mode 100644 include/etl/experimental/crc.h create mode 100644 include/etl/experimental/crc16.h create mode 100644 include/etl/experimental/crc16_aug_ccitt.h create mode 100644 include/etl/experimental/crc16_ccitt.h create mode 100644 include/etl/experimental/crc16_genibus.h create mode 100644 include/etl/experimental/crc16_kermit.h create mode 100644 include/etl/experimental/crc16_modbus.h create mode 100644 include/etl/experimental/crc16_usb.h create mode 100644 include/etl/experimental/crc16_x25.h create mode 100644 include/etl/experimental/crc16_xmodem.h create mode 100644 include/etl/experimental/crc32.h create mode 100644 include/etl/experimental/crc64_ecma.h create mode 100644 include/etl/experimental/crc8_ccitt.h create mode 100644 include/etl/experimental/crc8_rohc.h create mode 100644 include/etl/experimental/crc8_table16.h create mode 100644 include/etl/experimental/crc8_table256.h create mode 100644 include/etl/experimental/crc8_table4.h create mode 100644 include/etl/experimental/crc_implementation.h create mode 100644 include/etl/experimental/crc_parameters.h create mode 100644 include/etl/experimental/crc_table_16.h create mode 100644 include/etl/experimental/crc_table_256.h create mode 100644 include/etl/experimental/crc_table_4.h create mode 100644 include/etl/experimental/crc_table_generator.h create mode 100644 test/test_crc_table16.cpp create mode 100644 test/test_crc_table256.cpp create mode 100644 test/test_crc_table4.cpp diff --git a/include/etl/binary.h b/include/etl/binary.h index cebaa91f..5260485f 100644 --- a/include/etl/binary.h +++ b/include/etl/binary.h @@ -472,6 +472,9 @@ namespace etl return second ^ ((second ^ first) & MASK); } + template + struct reverse_bits_const; + #if ETL_8BIT_SUPPORT //*************************************************************************** /// Reverse 8 bits. @@ -486,10 +489,39 @@ namespace etl return value; } + //*********************************** inline ETL_CONSTEXPR14 int8_t reverse_bits(int8_t value) { return int8_t(reverse_bits(uint8_t(value))); } + + //*********************************** + template + struct reverse_bits_const + { + private: + + static ETL_CONSTANT uint8_t value1 = uint8_t(((Value & 0xAA) >> 1) | ((Value & 0x55) << 1)); + static ETL_CONSTANT uint8_t value2 = uint8_t(((value1 & 0xCC) >> 2) | ((value1 & 0x33) << 2)); + + public: + + static ETL_CONSTANT uint8_t value = uint8_t((value2 >> 4) | (value2 << 4)); + }; + + //*********************************** + template + struct reverse_bits_const + { + private: + + static ETL_CONSTANT int8_t value1 = int8_t(((Value & 0xAA) >> 1) | ((Value & 0x55) << 1)); + static ETL_CONSTANT int8_t value2 = int8_t(((value1 & 0xCC) >> 2) | ((value1 & 0x33) << 2)); + + public: + + static ETL_CONSTANT int8_t value = int8_t((value2 >> 4) | (value2 << 4)); + }; #endif //*************************************************************************** @@ -506,11 +538,42 @@ namespace etl return value; } + //*********************************** inline ETL_CONSTEXPR14 int16_t reverse_bits(int16_t value) { return int16_t(reverse_bits(uint16_t(value))); } + //*********************************** + template + struct reverse_bits_const + { + private: + + static ETL_CONSTANT uint16_t value1 = uint16_t(((Value & 0xAAAA) >> 1) | ((Value & 0x5555) << 1)); + static ETL_CONSTANT uint16_t value2 = uint16_t(((value1 & 0xCCCC) >> 2) | ((value1 & 0x3333) << 2)); + static ETL_CONSTANT uint16_t value3 = uint16_t(((value2 & 0xF0F0) >> 4) | ((value2 & 0x0F0F) << 4)); + + public: + + static ETL_CONSTANT uint16_t value = uint16_t((value3 >> 8) | (value3 << 8)); + }; + + //*********************************** + template + struct reverse_bits_const + { + private: + + static ETL_CONSTANT int16_t value1 = int16_t(((Value & 0xAAAA) >> 1) | ((Value & 0x5555) << 1)); + static ETL_CONSTANT int16_t value2 = int16_t(((value1 & 0xCCCC) >> 2) | ((value1 & 0x3333) << 2)); + static ETL_CONSTANT int16_t value3 = int16_t(((value2 & 0xF0F0) >> 4) | ((value2 & 0x0F0F) << 4)); + + public: + + static ETL_CONSTANT int16_t value = int16_t((value3 >> 8) | (value3 << 8)); + }; + //*************************************************************************** /// Reverse 32 bits. ///\ingroup binary @@ -526,11 +589,44 @@ namespace etl return value; } + //*********************************** inline ETL_CONSTEXPR14 int32_t reverse_bits(int32_t value) { return int32_t(reverse_bits(uint32_t(value))); } + //*********************************** + template + struct reverse_bits_const + { + private: + + static ETL_CONSTANT uint32_t value1 = uint32_t(((Value & 0xAAAAAAAA) >> 1) | ((Value & 0x55555555) << 1)); + static ETL_CONSTANT uint32_t value2 = uint32_t(((value1 & 0xCCCCCCCC) >> 2) | ((value1 & 0x33333333) << 2)); + static ETL_CONSTANT uint32_t value3 = uint32_t(((value2 & 0xF0F0F0F0) >> 4) | ((value2 & 0x0F0F0F0F) << 4)); + static ETL_CONSTANT uint32_t value4 = uint32_t(((value3 & 0xFF00FF00) >> 8) | ((value3 & 0x00FF00FF) << 8)); + + public: + + static ETL_CONSTANT uint32_t value = uint32_t((value4 >> 16) | (value4 << 16)); + }; + + //*********************************** + template + struct reverse_bits_const + { + private: + + static ETL_CONSTANT int32_t value1 = int32_t(((Value & 0xAAAAAAAA) >> 1) | ((Value & 0x55555555) << 1)); + static ETL_CONSTANT int32_t value2 = int32_t(((value1 & 0xCCCCCCCC) >> 2) | ((value1 & 0x33333333) << 2)); + static ETL_CONSTANT int32_t value3 = int32_t(((value2 & 0xF0F0F0F0) >> 4) | ((value2 & 0x0F0F0F0F) << 4)); + static ETL_CONSTANT int32_t value4 = int32_t(((value3 & 0xFF00FF00) >> 8) | ((value3 & 0x00FF00FF) << 8)); + + public: + + static ETL_CONSTANT int32_t value = int32_t((value4 >> 16) | (value4 << 16)); + }; + #if ETL_USING_64BIT_TYPES //*************************************************************************** /// Reverse 64 bits. @@ -548,10 +644,45 @@ namespace etl return value; } + //*********************************** inline ETL_CONSTEXPR14 int64_t reverse_bits(int64_t value) { return int64_t(reverse_bits(uint64_t(value))); } + + //*********************************** + template + struct reverse_bits_const + { + private: + + static ETL_CONSTANT uint64_t value1 = uint64_t(((Value & 0xAAAAAAAAAAAAAAAA) >> 1) | ((Value & 0x5555555555555555) << 1)); + static ETL_CONSTANT uint64_t value2 = uint64_t(((value1 & 0xCCCCCCCCCCCCCCCC) >> 2) | ((value1 & 0x3333333333333333) << 2)); + static ETL_CONSTANT uint64_t value3 = uint64_t(((value2 & 0xF0F0F0F0F0F0F0F0) >> 4) | ((value2 & 0x0F0F0F0F0F0F0F0F) << 4)); + static ETL_CONSTANT uint64_t value4 = uint64_t(((value3 & 0xFF00FF00FF00FF00) >> 8) | ((value3 & 0x00FF00FF00FF00FF) << 8)); + static ETL_CONSTANT uint64_t value5 = uint64_t(((value4 & 0xFFFF0000FFFF0000) >> 16) | ((value4 & 0x0000FFFF0000FFFF) << 16)); + + public: + + static ETL_CONSTANT uint64_t value = uint64_t((value5 >> 32) | (value5 << 32)); + }; + + //*********************************** + template + struct reverse_bits_const + { + private: + + static ETL_CONSTANT int64_t value1 = int64_t(((Value & 0xAAAAAAAAAAAAAAAA) >> 1) | ((Value & 0x5555555555555555) << 1)); + static ETL_CONSTANT int64_t value2 = int64_t(((value1 & 0xCCCCCCCCCCCCCCCC) >> 2) | ((value1 & 0x3333333333333333) << 2)); + static ETL_CONSTANT int64_t value3 = int64_t(((value2 & 0xF0F0F0F0F0F0F0F0) >> 4) | ((value2 & 0x0F0F0F0F0F0F0F0F) << 4)); + static ETL_CONSTANT int64_t value4 = int64_t(((value3 & 0xFF00FF00FF00FF00) >> 8) | ((value3 & 0x00FF00FF00FF00FF) << 8)); + static ETL_CONSTANT int64_t value5 = int64_t(((value4 & 0xFFFF0000FFFF0000) >> 16) | ((value4 & 0x0000FFFF0000FFFF) << 16)); + + public: + + static ETL_CONSTANT int64_t value = int64_t((value5 >> 32) | (value5 << 32)); + }; #endif //*************************************************************************** diff --git a/include/etl/experimental/crc.h b/include/etl/experimental/crc.h new file mode 100644 index 00000000..4948719d --- /dev/null +++ b/include/etl/experimental/crc.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_CCITT_EXP_INCLUDED +#define ETL_CRC8_CCITT_EXP_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" +#include "crc_parameters.h" + +namespace etl +{ + namespace crc + { +#if ETL_CPP11_SUPPORTED + template + using crc8_ccitt_t = etl::private_crc::crc_type; +#else + template + class crc8_ccitt_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_ccitt_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_ccitt_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef crc8_ccitt_t<256U> crc8_ccitt_t256; + typedef crc8_ccitt_t<16U> crc8_ccitt_t16; + typedef crc8_ccitt_t<4U> crc8_ccitt_t4; + typedef crc8_ccitt_t256 crc8_ccitt; + } +} + +#endif diff --git a/include/etl/experimental/crc16.h b/include/etl/experimental/crc16.h new file mode 100644 index 00000000..e09a1031 --- /dev/null +++ b/include/etl/experimental/crc16.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_EX_INCLUDED +#define ETL_CRC16_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc16 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc16_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc16_t<256U> crc16_t256; + typedef etl::crc::crc16_t<16U> crc16_t16; + typedef etl::crc::crc16_t<4U> crc16_t4; + typedef crc16_t256 crc16; + } +} +#endif diff --git a/include/etl/experimental/crc16_aug_ccitt.h b/include/etl/experimental/crc16_aug_ccitt.h new file mode 100644 index 00000000..13b49212 --- /dev/null +++ b/include/etl/experimental/crc16_aug_ccitt.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_AUG_CCITT_EX_INCLUDED +#define ETL_CRC16_AUG_CCITT_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc16_aug_ccitt 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc16_aug_ccitt_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_aug_ccitt_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_aug_ccitt_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc16_aug_ccitt_t<256U> crc16_aug_ccitt_t256; + typedef etl::crc::crc16_aug_ccitt_t<16U> crc16_aug_ccitt_t16; + typedef etl::crc::crc16_aug_ccitt_t<4U> crc16_aug_ccitt_t4; + typedef crc16_aug_ccitt_t256 crc16_aug_ccitt; + } +} +#endif diff --git a/include/etl/experimental/crc16_ccitt.h b/include/etl/experimental/crc16_ccitt.h new file mode 100644 index 00000000..e2f12d31 --- /dev/null +++ b/include/etl/experimental/crc16_ccitt.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_CCITT_EX_INCLUDED +#define ETL_CRC16_CCITT_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc16_ccitt 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc16_ccitt_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_ccitt_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_ccitt_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc16_ccitt_t<256U> crc16_ccitt_t256; + typedef etl::crc::crc16_ccitt_t<16U> crc16_ccitt_t16; + typedef etl::crc::crc16_ccitt_t<4U> crc16_ccitt_t4; + typedef crc16_ccitt_t256 crc16_ccitt; + } +} +#endif diff --git a/include/etl/experimental/crc16_genibus.h b/include/etl/experimental/crc16_genibus.h new file mode 100644 index 00000000..72a5d1b7 --- /dev/null +++ b/include/etl/experimental/crc16_genibus.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_GENIBUS_EX_INCLUDED +#define ETL_CRC16_GENIBUS_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc16_genibus 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc16_genibus_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_genibus_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_genibus_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc16_genibus_t<256U> crc16_genibus_t256; + typedef etl::crc::crc16_genibus_t<16U> crc16_genibus_t16; + typedef etl::crc::crc16_genibus_t<4U> crc16_genibus_t4; + typedef crc16_genibus_t256 crc16_genibus; + } +} +#endif diff --git a/include/etl/experimental/crc16_kermit.h b/include/etl/experimental/crc16_kermit.h new file mode 100644 index 00000000..dcb026ca --- /dev/null +++ b/include/etl/experimental/crc16_kermit.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_KERMIT_EX_INCLUDED +#define ETL_CRC16_KERMIT_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc16_kermit 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc16_kermit_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_kermit_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_kermit_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc16_kermit_t<256U> crc16_kermit_t256; + typedef etl::crc::crc16_kermit_t<16U> crc16_kermit_t16; + typedef etl::crc::crc16_kermit_t<4U> crc16_kermit_t4; + typedef crc16_kermit_t256 crc16_kermit; + } +} +#endif diff --git a/include/etl/experimental/crc16_modbus.h b/include/etl/experimental/crc16_modbus.h new file mode 100644 index 00000000..cc62a179 --- /dev/null +++ b/include/etl/experimental/crc16_modbus.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_MODBUS_EX_INCLUDED +#define ETL_CRC16_MODBUS_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc16_modbus 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc16_modbus_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_modbus_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_modbus_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc16_modbus_t<256U> crc16_modbus_t256; + typedef etl::crc::crc16_modbus_t<16U> crc16_modbus_t16; + typedef etl::crc::crc16_modbus_t<4U> crc16_modbus_t4; + typedef crc16_modbus_t256 crc16_modbus; + } +} +#endif diff --git a/include/etl/experimental/crc16_usb.h b/include/etl/experimental/crc16_usb.h new file mode 100644 index 00000000..e1205999 --- /dev/null +++ b/include/etl/experimental/crc16_usb.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_USB_EX_INCLUDED +#define ETL_CRC16_USB_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc16_usb 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc16_usb_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_usb_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_usb_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc16_usb_t<256U> crc16_usb_t256; + typedef etl::crc::crc16_usb_t<16U> crc16_usb_t16; + typedef etl::crc::crc16_usb_t<4U> crc16_usb_t4; + typedef crc16_usb_t256 crc16_usb; + } +} +#endif diff --git a/include/etl/experimental/crc16_x25.h b/include/etl/experimental/crc16_x25.h new file mode 100644 index 00000000..d423d342 --- /dev/null +++ b/include/etl/experimental/crc16_x25.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_X25_EX_INCLUDED +#define ETL_CRC16_X25_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc16_x25 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc16_x25_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_x25_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_x25_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc16_x25_t<256U> crc16_x25_t256; + typedef etl::crc::crc16_x25_t<16U> crc16_x25_t16; + typedef etl::crc::crc16_x25_t<4U> crc16_x25_t4; + typedef crc16_x25_t256 crc16_x25; + } +} +#endif diff --git a/include/etl/experimental/crc16_xmodem.h b/include/etl/experimental/crc16_xmodem.h new file mode 100644 index 00000000..c0d1921b --- /dev/null +++ b/include/etl/experimental/crc16_xmodem.h @@ -0,0 +1,87 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_XMODEM_EX_INCLUDED +#define ETL_CRC16_XMODEM_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc16_xmodem 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { +#if ETL_CPP11_SUPPORTED + template + using crc16_xmodem_t = etl::private_crc::crc_type; +#else + template + class crc16_xmodem_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_xmodem_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_xmodem_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc::crc16_xmodem_t<256U> crc16_xmodem_t256; + typedef etl::crc::crc16_xmodem_t<16U> crc16_xmodem_t16; + typedef etl::crc::crc16_xmodem_t<4U> crc16_xmodem_t4; + typedef crc16_xmodem_t256 crc16_xmodem; + } +} +#endif diff --git a/include/etl/experimental/crc32.h b/include/etl/experimental/crc32.h new file mode 100644 index 00000000..5fd6b37e --- /dev/null +++ b/include/etl/experimental/crc32.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC32_EX_INCLUDED +#define ETL_CRC32_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc32 32 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc32_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc32_t<256U> crc32_t256; + typedef etl::crc::crc32_t<16U> crc32_t16; + typedef etl::crc::crc32_t<4U> crc32_t4; + typedef crc32_t256 crc32; + } +} +#endif diff --git a/include/etl/experimental/crc64_ecma.h b/include/etl/experimental/crc64_ecma.h new file mode 100644 index 00000000..adb3980d --- /dev/null +++ b/include/etl/experimental/crc64_ecma.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC64_ECMA_EX_INCLUDED +#define ETL_CRC64_ECMA_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc64_ecma 64 bit ECMA CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc64_ecma_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc64_ecma_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc64_ecma_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc64_ecma_t<256U> crc64_ecma_t256; + typedef etl::crc::crc64_ecma_t<16U> crc64_ecma_t16; + typedef etl::crc::crc64_ecma_t<4U> crc64_ecma_t4; + typedef crc64_ecma_t256 crc64_ecma; + } +} +#endif diff --git a/include/etl/experimental/crc8_ccitt.h b/include/etl/experimental/crc8_ccitt.h new file mode 100644 index 00000000..156944b4 --- /dev/null +++ b/include/etl/experimental/crc8_ccitt.h @@ -0,0 +1,83 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_CCITT_EXP_INCLUDED +#define ETL_CRC8_CCITT_EXP_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup crc8_ccitt 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc8_ccitt_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_ccitt_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_ccitt_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc8_ccitt_t<256U> crc8_ccitt_t256; + typedef etl::crc::crc8_ccitt_t<16U> crc8_ccitt_t16; + typedef etl::crc::crc8_ccitt_t<4U> crc8_ccitt_t4; + typedef crc8_ccitt_t256 crc8_ccitt; + } +} + +#endif diff --git a/include/etl/experimental/crc8_rohc.h b/include/etl/experimental/crc8_rohc.h new file mode 100644 index 00000000..baa4a3a0 --- /dev/null +++ b/include/etl/experimental/crc8_rohc.h @@ -0,0 +1,83 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_ROHC_EXP_INCLUDED +#define ETL_CRC8_ROHC_EXP_INCLUDED + +#include "../platform.h" +#include "crc_implementation.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + +///\defgroup rohc 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { + template + class crc8_rohc_t : public etl::private_crc::crc_type + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_rohc_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_rohc_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + + typedef etl::crc::crc8_rohc_t<256U> crc8_rohc_t256; + typedef etl::crc::crc8_rohc_t<16U> crc8_rohc_t16; + typedef etl::crc::crc8_rohc_t<4U> crc8_rohc_t4; + typedef crc8_rohc_t256 crc8_rohc; + } +} + +#endif diff --git a/include/etl/experimental/crc8_table16.h b/include/etl/experimental/crc8_table16.h new file mode 100644 index 00000000..e7ad5988 --- /dev/null +++ b/include/etl/experimental/crc8_table16.h @@ -0,0 +1,234 @@ + +#pragma once + +#include "../platform.h" +#include "../frame_check_sequence.h" + +#include "../binary.h" + +#include "stdint.h" + +namespace etl +{ + namespace crc + { + //***************************************************************************** + // + //***************************************************************************** + template + struct crc8_policy_table16; + + //***************************************************************************** + // Specialisation for Reflect = false + //***************************************************************************** + template + struct crc8_policy_table16 + { + static ETL_CONSTANT uint8_t Mask = 0x0FU; + static ETL_CONSTANT uint8_t Chunk_Size = 4U; + + typedef uint8_t value_type; + + //***************************************************************************** + template + class entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT bool Do_Poly = (Entry & (uint8_t(1U) << (Accumulator_Bits - 1U))) != 0U; + static ETL_CONSTANT uint8_t value = uint8_t(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); + }; + + //************************************************************************* + template + class table_entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = entry::Accumulator_Bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_Size); + static ETL_CONSTANT uint8_t Entry = uint8_t(Index << Shift_Bits); + + static ETL_CONSTANT uint8_t value = entry::value>::value>::value>::value; + }; + + //************************************************************************* + ETL_CONSTEXPR uint8_t initial() const + { + return Initial; + } + + //************************************************************************* + uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* table) const + { + // Extract the most significant nibble of the crc and xor with the value nibble. + uint8_t index = (crc >> (etl::integral_limits::bits - Chunk_Size)) ^ value; + + crc <<= Chunk_Size; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + uint8_t add(uint8_t crc, uint8_t value) const + { + static ETL_CONSTANT uint8_t table[16] = + { + table_entry<0U, Polynomial>::value, + table_entry<1U, Polynomial>::value, + table_entry<2U, Polynomial>::value, + table_entry<3U, Polynomial>::value, + table_entry<4U, Polynomial>::value, + table_entry<5U, Polynomial>::value, + table_entry<6U, Polynomial>::value, + table_entry<7U, Polynomial>::value, + table_entry<8U, Polynomial>::value, + table_entry<9U, Polynomial>::value, + table_entry<10U, Polynomial>::value, + table_entry<11U, Polynomial>::value, + table_entry<12U, Polynomial>::value, + table_entry<13U, Polynomial>::value, + table_entry<14U, Polynomial>::value, + table_entry<15U, Polynomial>::value + }; + + crc = update_chunk(crc, (value >> Chunk_Size) & Mask, table); + crc = update_chunk(crc, value & Mask, table); + + return crc; + } + + //************************************************************************* + uint8_t final(uint8_t crc) const + { + return crc ^ Xor_Out; + } + }; + + //***************************************************************************** + // Specialisation for Reflect = true + //***************************************************************************** + template + struct crc8_policy_table16 + { + static ETL_CONSTANT uint8_t Mask = 0x0FU; + static ETL_CONSTANT uint8_t Chunk_Size = 4U; + + typedef uint8_t value_type; + + //***************************************************************************** + template + class entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT bool Do_Poly = (Entry & uint8_t(1U)) != 0U; + static ETL_CONSTANT uint8_t value = uint8_t(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const::value : (Entry >> 1U)); + }; + + //************************************************************************* + template + class table_entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = entry::Accumulator_Bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_Size); + static ETL_CONSTANT uint8_t Entry = uint8_t(Index << Shift_Bits); + + static ETL_CONSTANT uint8_t value = entry::value>::value>::value>::value; + }; + + //************************************************************************* + ETL_CONSTEXPR uint8_t initial() const + { + return Initial; + } + + //************************************************************************* + uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* const table) const + { + // Extract the most significant nibble of the crc and xor with the value nibble. + uint8_t index = (crc >> (Accumulator_Bits - 4U)) ^ value; + + crc <<= Chunk_Size; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + uint8_t add(uint8_t crc, uint8_t value) const + { + static ETL_CONSTANT uint8_t table[16] = + { + table_entry<0U, Polynomial>::value, + table_entry<1U, Polynomial>::value, + table_entry<2U, Polynomial>::value, + table_entry<3U, Polynomial>::value, + table_entry<4U, Polynomial>::value, + table_entry<5U, Polynomial>::value, + table_entry<6U, Polynomial>::value, + table_entry<7U, Polynomial>::value, + table_entry<8U, Polynomial>::value, + table_entry<9U, Polynomial>::value, + table_entry<10U, Polynomial>::value, + table_entry<11U, Polynomial>::value, + table_entry<12U, Polynomial>::value, + table_entry<13U, Polynomial>::value, + table_entry<14U, Polynomial>::value, + table_entry<15U, Polynomial>::value + }; + + crc = update_chunk(crc, (value >> Chunk_Size) & Mask, table); // high nibble + crc = update_chunk(crc, value & Mask, table); // low nibble + + return crc; + } + + //************************************************************************* + uint8_t final(uint8_t crc) const + { + return crc ^ Xor_Out; + } + }; + + //***************************************************************************** + // + //***************************************************************************** + template + class crc8_table16 : public etl::frame_check_sequence > + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_table16() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_table16(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + } +} diff --git a/include/etl/experimental/crc8_table256.h b/include/etl/experimental/crc8_table256.h new file mode 100644 index 00000000..bd9c187c --- /dev/null +++ b/include/etl/experimental/crc8_table256.h @@ -0,0 +1,347 @@ + +#pragma once + +#include "../platform.h" +#include "../frame_check_sequence.h" +#include "../binary.h" + +#include "crc_common.h" + +#include "stdint.h" + +namespace etl +{ + namespace crc + { + //***************************************************************************** + // + //***************************************************************************** + template + struct crc8_policy_table256 + { + static ETL_CONSTANT uint8_t Chunk_Mask = etl::private_crc::crc_traits<256U>::Chunk_Mask; + static ETL_CONSTANT uint8_t Chunk_Bits = etl::private_crc::crc_traits<256U>::Chunk_Bits; + + typedef uint8_t value_type; + + //************************************************************************* + ETL_CONSTEXPR uint8_t initial() const + { + return Initial; + } + + //************************************************************************* + static uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* const table) + { + uint8_t t = crc ^ value; + + crc = table[t]; + + return crc; + } + + //************************************************************************* + uint8_t add(uint8_t crc, uint8_t value) const + { + static ETL_CONSTANT uint8_t table[256] = + { + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value, + etl::private_crc::table_entry::value + }; + + crc = update_chunk(crc, value, table); + + return crc; + } + + //************************************************************************* + uint8_t final(uint8_t crc) const + { + return crc ^ Xor_Out; + } + }; + + //***************************************************************************** + // + //***************************************************************************** + template + class crc8_table256 : public etl::frame_check_sequence > + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_table256() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_table256(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + } +} diff --git a/include/etl/experimental/crc8_table4.h b/include/etl/experimental/crc8_table4.h new file mode 100644 index 00000000..e69e815e --- /dev/null +++ b/include/etl/experimental/crc8_table4.h @@ -0,0 +1,212 @@ + +#pragma once + +#include "../platform.h" +#include "../frame_check_sequence.h" + +#include "../binary.h" + +#include "stdint.h" + +namespace etl +{ + namespace crc + { + //***************************************************************************** + // + //***************************************************************************** + template + struct crc8_policy_table4; + + //***************************************************************************** + // Specialisation for Reflect = false + //***************************************************************************** + template + struct crc8_policy_table4 + { + static ETL_CONSTANT uint8_t Mask = 0x03U; + static ETL_CONSTANT uint8_t Chunk_Size = 2U; + + typedef uint8_t value_type; + + //***************************************************************************** + template + class entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT bool Do_Poly = (Entry & (uint8_t(1U) << (Accumulator_Bits - 1U))) != 0U; + static ETL_CONSTANT uint8_t value = uint8_t(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); + }; + + //************************************************************************* + template + class table_entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = entry::Accumulator_Bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_Size); + static ETL_CONSTANT uint8_t Entry = uint8_t(Index << Shift_Bits); + + static ETL_CONSTANT uint8_t value = entry::value>::value; + }; + + //************************************************************************* + ETL_CONSTEXPR uint8_t initial() const + { + return Initial; + } + + //************************************************************************* + uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* table) const + { + // Extract the most significant nibble of the crc and xor with the value nibble. + uint8_t index = (crc >> (etl::integral_limits::bits - Chunk_Size)) ^ value; + + crc <<= Chunk_Size; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + uint8_t add(uint8_t crc, uint8_t value) const + { + static ETL_CONSTANT uint8_t table[4] = + { + table_entry<0U, Polynomial>::value, + table_entry<1U, Polynomial>::value, + table_entry<2U, Polynomial>::value, + table_entry<3U, Polynomial>::value + }; + + crc = update_chunk(crc, (value >> (Chunk_Size * 3U)) & Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Size * 2U)) & Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Size * 1U)) & Mask, table); + crc = update_chunk(crc, value & Mask, table); + + return crc; + } + + //************************************************************************* + uint8_t final(uint8_t crc) const + { + return crc ^ Xor_Out; + } + }; + + //***************************************************************************** + // Specialisation for Reflect = true + //***************************************************************************** + template + struct crc8_policy_table4 + { + static ETL_CONSTANT uint8_t Mask = 0x03; + static ETL_CONSTANT uint8_t Chunk_Size = 2U; + + typedef uint8_t value_type; + + //***************************************************************************** + template + class entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT bool Do_Poly = (Entry & uint8_t(1U)) != 0U; + static ETL_CONSTANT uint8_t value = uint8_t(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const::value : (Entry >> 1U)); + }; + + //************************************************************************* + template + class table_entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = entry::Accumulator_Bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_Size); + static ETL_CONSTANT uint8_t Entry = uint8_t(Index << Shift_Bits); + + static ETL_CONSTANT uint8_t value = entry::value>::value>::value>::value; + }; + + //************************************************************************* + ETL_CONSTEXPR uint8_t initial() const + { + return Initial; + } + + //************************************************************************* + uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* const table) const + { + // Extract the most significant nibble of the crc and xor with the value nibble. + uint8_t index = (crc >> (Accumulator_Bits - Chunk_Size)) ^ value; + + crc <<= Chunk_Size; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + uint8_t add(uint8_t crc, uint8_t value) const + { + static ETL_CONSTANT uint8_t table[4] = + { + table_entry<0U, Polynomial>::value, + table_entry<1U, Polynomial>::value, + table_entry<2U, Polynomial>::value, + table_entry<3U, Polynomial>::value + }; + + crc = update_chunk(crc, (value >> (Chunk_Size * 3U)) & Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Size * 2U)) & Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Size * 1U)) & Mask, table); + crc = update_chunk(crc, value & Mask, table); + + return crc; + } + + //************************************************************************* + uint8_t final(uint8_t crc) const + { + return crc ^ Xor_Out; + } + }; + + //***************************************************************************** + // + //***************************************************************************** + template + class crc8_table4 : public etl::frame_check_sequence > + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_table4() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_table4(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + } +} diff --git a/include/etl/experimental/crc_implementation.h b/include/etl/experimental/crc_implementation.h new file mode 100644 index 00000000..2935cda6 --- /dev/null +++ b/include/etl/experimental/crc_implementation.h @@ -0,0 +1,656 @@ + +#pragma once + +#include "../platform.h" +#include "../frame_check_sequence.h" +#include "../static_assert.h" +#include "../binary.h" + +#include "stdint.h" + +namespace etl +{ + namespace private_crc + { + //***************************************************************************** + /// CRC Traits + //***************************************************************************** + template + struct crc_traits + { + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + }; + + //********************************* + // Traits for table size of 4. + template <> + struct crc_traits<4U> + { + static ETL_CONSTANT uint8_t Chunk_Mask = 0x03U; + static ETL_CONSTANT size_t Chunk_Bits = 2U; + }; + + //********************************* + // Traits for table size of 16. + template <> + struct crc_traits<16U> + { + static ETL_CONSTANT uint8_t Chunk_Mask = 0x0FU; + static ETL_CONSTANT size_t Chunk_Bits = 4U; + }; + + //********************************* + // Traits for table size of 256. + template <> + struct crc_traits<256U> + { + static ETL_CONSTANT uint8_t Chunk_Mask = 0xFFU; + static ETL_CONSTANT size_t Chunk_Bits = 8U; + }; + + //***************************************************************************** + /// CRC Entry + //***************************************************************************** + template + class crc_entry; + + //********************************* + // Not reflected + template + class crc_entry + { + private: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1U))) != 0U; + + public: + + static ETL_CONSTANT TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); + }; + + //********************************* + // Reflected + template + class crc_entry + { + private: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT bool Do_Poly = (Entry & TAccumulator(1U)) != 0U; + + public: + + static ETL_CONSTANT TAccumulator value = TAccumulator(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const::value : (Entry >> 1U)); + }; + + //***************************************************************************** + /// CRC Table Entry + //***************************************************************************** + template + class crc_table_entry + { + ETL_STATIC_ASSERT((Chunk_Bits == 2U) || (Chunk_Bits == 4U) || (Chunk_Bits == 8U), "Chunk bits must be 2, 4 or 8"); + }; + + //********************************* + // Chunk bit size of 8. + template + class crc_table_entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 8U); + static ETL_CONSTANT TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); + + static ETL_CONSTANT TAccumulator value = crc_entry::value>::value>::value>::value>::value>::value>::value>::value; + }; + + //********************************* + // Chunk bit size of 4. + template + class crc_table_entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 4U); + static ETL_CONSTANT TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); + + static const TAccumulator value = crc_entry::value>::value>::value>::value; + }; + + //********************************* + // Chunk bit size of 2. + template + class crc_table_entry + { + public: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 2U); + static ETL_CONSTANT TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); + + static const TAccumulator value = crc_entry::value>::value; + }; + + //************************************************************************* + // Accumulator_Bits > Chunk_Bits and not reflected + template + typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && !Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + + crc <<= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + // Accumulator_Bits > Chunk_Bits and reflected + template + typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + size_t index = (crc & Chunk_Mask) ^ value; + + crc >>= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + // Accumulator_Bits == Chunk_Bits and not reflected + template + typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && !Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + + crc = table[index]; + + return crc; + } + + //************************************************************************* + // Accumulator_Bits == Chunk_Bits and reflected + template + typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + size_t index = (crc & Chunk_Mask) ^ value; + + crc = table[index]; + + return crc; + } + + //***************************************************************************** + // + //***************************************************************************** + template + struct crc_policy + { + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + }; + + //********************************* + template + struct crc_policy + { + static ETL_CONSTANT size_t Table_Size = 256U; + static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; + static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + + typedef TAccumulator value_type; + + //************************************************************************* + ETL_CONSTEXPR TAccumulator initial() const + { + return Initial; + } + + //************************************************************************* + TAccumulator add(TAccumulator crc, uint8_t value) const + { + static ETL_CONSTANT TAccumulator table[Table_Size] = + { + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value + }; + + crc = crc_update_chunk(crc, value, table); + + return crc; + } + + //************************************************************************* + TAccumulator final(TAccumulator crc) const + { + return crc ^ Xor_Out; + } + }; + + //********************************* + template + struct crc_policy + { + static ETL_CONSTANT size_t Table_Size = 16U; + static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; + static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + + typedef TAccumulator value_type; + + //************************************************************************* + ETL_CONSTEXPR TAccumulator initial() const + { + return Initial; + } + + //************************************************************************* + static TAccumulator update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + // Extract the most significant nibble of the crc and xor with the value nibble. + size_t index = (crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value; + + crc <<= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + TAccumulator add(TAccumulator crc, uint8_t value) const + { + static ETL_CONSTANT TAccumulator table[Table_Size] = + { + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value + }; + + crc = update_chunk(crc, (value >> Chunk_Bits) & Chunk_Mask, table); + crc = update_chunk(crc, value & Chunk_Mask, table); + + return crc; + } + + //************************************************************************* + TAccumulator final(TAccumulator crc) const + { + return crc ^ Xor_Out; + } + }; + + + //********************************* + template + struct crc_policy + { + static ETL_CONSTANT size_t Table_Size = 4U; + static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; + static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + + typedef TAccumulator value_type; + + //************************************************************************* + ETL_CONSTEXPR TAccumulator initial() const + { + return Initial; + } + + //************************************************************************* + static TAccumulator update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + // Extract the most significant nibble of the crc and xor with the value nibble. + size_t index = (crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value; + + crc <<= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + TAccumulator add(TAccumulator crc, uint8_t value) const + { + static ETL_CONSTANT TAccumulator table[Table_Size] = + { + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value + }; + + crc = update_chunk(crc, (value >> (Chunk_Bits * 3U)) & Chunk_Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Bits * 2U)) & Chunk_Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Bits * 1U)) & Chunk_Mask, table); + crc = update_chunk(crc, value & Chunk_Mask, table); + + return crc; + } + + //************************************************************************* + TAccumulator final(TAccumulator crc) const + { + return crc ^ Xor_Out; + } + }; + + //***************************************************************************** + /// + //***************************************************************************** + template + class crc_type : public etl::frame_check_sequence > + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc_type() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc_type(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; + } +} diff --git a/include/etl/experimental/crc_parameters.h b/include/etl/experimental/crc_parameters.h new file mode 100644 index 00000000..309dbdf4 --- /dev/null +++ b/include/etl/experimental/crc_parameters.h @@ -0,0 +1,42 @@ +#pragma once + +#include "../platform.h" + +namespace etl +{ + namespace private_crc + { + template + struct crc_parameters + { + typedef TAccumulator accumulator_type; + static ETL_CONSTANT TAccumulator Polynomial = Polynomial_; + static ETL_CONSTANT TAccumulator Initial = Initial_; + static ETL_CONSTANT TAccumulator Xor_Out = Xor_Out_; + static ETL_CONSTANT bool Reflect = Reflect_; + }; + + // 8 bit. + typedef crc_parameters crc8_ccitt_parameters; + typedef crc_parameters crc8_rohc_parameters; + + // 16 bit. + typedef crc_parameters crc16_parameters; + typedef crc_parameters crc16_ccitt_parameters; + typedef crc_parameters crc16_aug_ccitt_parameters; + typedef crc_parameters crc16_genibus_parameters; + typedef crc_parameters crc16_kermit_parameters; + typedef crc_parameters crc16_modbus_parameters; + typedef crc_parameters crc16_usb_parameters; + typedef crc_parameters crc16_x25_parameters; + typedef crc_parameters crc16_xmodem_parameters; + + // 32 bit. + typedef crc_parameters crc32_parameters; + + // 64 bit. + typedef crc_parameters crc64_ecma_parameters; + } +} + + diff --git a/include/etl/experimental/crc_table_16.h b/include/etl/experimental/crc_table_16.h new file mode 100644 index 00000000..05cb77f8 --- /dev/null +++ b/include/etl/experimental/crc_table_16.h @@ -0,0 +1,701 @@ + +#pragma once + +#include +#include + +//***************************************************************************** +template +class entry +{ +private: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1))) != 0U; + +public: + + static const TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); +}; + +//***************************************************************************** +/// 8 bit chunks +//***************************************************************************** +template +class table_entry_8 +{ +//private: +public: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const size_t Shift_Bits = size_t(Accumulator_Bits - 8U); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value>::value>::value>::value>::value>::value>::value; +}; + +//***************************************************************************** +/// 4 bit chunks +//***************************************************************************** +template +class table_entry_4 +{ +private: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_4_Bits); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value>::value>::value; +}; + +//***************************************************************************** +/// 2 bit chunks +//***************************************************************************** +template +class table_entry_2 +{ +private: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_2_Bits); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value; +}; + +//***************************************************************************** +template +struct crc_table; + +template +struct crc_table +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[256] = + { + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value + }; + + return table; + } +}; + +template +struct crc_table +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[16] = + { + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value + }; + + return table; + } +}; + +template +struct crc_table +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[4] = + { + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value + }; + + return table; + } +}; + + +// +// Define the CRC algorithm parameters +// +template +struct crc_algorithm +{ + using accumulator_type = TAccumulator; + static constexpr TAccumulator polynomial = Polynomial; + static constexpr TAccumulator initial_value = Initial; + static constexpr TAccumulator xor_out_value = Xor_Out; + static constexpr bool reverse = Reverse; +}; + +// +// Define the basic traits we use in our CRC accumulators and Table Lookup +// +template +struct crc_traits {}; + +template +struct crc_traits +{ + static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; + static constexpr std::size_t CHUNK_BITS = 2; + static constexpr uint8_t CHUNK_MASK = 0x03u; + static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; + + using table_type = std::array; +}; + +template +struct crc_traits +{ + static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; + static constexpr std::size_t CHUNK_BITS = 4; + static constexpr uint8_t CHUNK_MASK = 0x0Fu; + static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; + + using table_type = std::array; +}; + +template +struct crc_traits +{ + static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; + static constexpr std::size_t CHUNK_BITS = 8; + static constexpr uint8_t CHUNK_MASK = 0xFFu; + static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; + + using table_type = std::array; +}; + +// +// CRC rotation policies. +// +// Forward rotation means that we clock in data MSB->LSB and rotate the Accumulator register left +// Reverse rotation means that we clock in data LSB->MSB and rotate the Accumulator register right +// + +template +struct crc_forward_policy +{ + using traits = crc_traits; + + + [[nodiscard]] static constexpr TAccumulator update_impl_tiny( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_small( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_large( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value, table); // full byte + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_chunk( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + // ensure we have only 4 bits + value &= traits::CHUNK_MASK; + + // Extract the most significant nibble of the crc and xor with the value nibble + uint8_t t = (crc >> (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS)) ^ value; + + // special case for when chunk size is same as accumulator size. + if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { + // shit crc left the size of the nibble + crc <<= traits::CHUNK_BITS; + + // xor in the table data + crc ^= table[t]; + } + else { + crc = table[t]; + } + + return crc; + } + + [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) + { + // initialise with the register in the upper bits + TAccumulator entry = TAccumulator(index) << (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS); + + for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) + { + // We are processing MSBs / rotating left so we need to check the high bit + if (entry & (TAccumulator(1u) << (traits::ACCUMULATOR_BITS - 1))) { + entry = (entry << 1) ^ polynomial; + } + else { + entry = (entry << 1); + } + } + + return entry; + } + + [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) + { + return init; + } +}; + +template +struct crc_reverse_policy +{ + using traits = crc_traits; + + + [[nodiscard]] static constexpr TAccumulator update_impl_tiny( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_small( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble + crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_large( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value, table); // full byte + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_chunk( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + // ensure we have only 4 bits + value &= traits::CHUNK_MASK; + + // Extract the least significant nibble of the crc and xor with the value nibble + uint8_t t = (crc & traits::CHUNK_MASK) ^ value; + + // special case for when chunk size is same as accumulator size. + if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { + // shit crc right the size of a nibble + crc >>= traits::CHUNK_BITS; + + // xor in the table data + crc ^= table[t]; + } + else { + crc = table[t]; + } + + return crc; + } + + [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) + { + // initialise with the register in the lower bits + TAccumulator entry = TAccumulator(index); + + for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) + { + // we are processing LSBs/rotating right + if (entry & 0x1u) { + entry = (entry >> 1) ^ util::reverse_bits(polynomial); + } + else { + entry = (entry >> 1); + } + } + + return entry; + } + + [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) + { + return util::reverse_bits(init); + } +}; + + +// +// A generic CRC lookup table sized for computing a nibble (4 bits) at a time. +// +// This is can be a large reduction of table space storage for embedded devices. +// +template ::value>> +class crc_chunk_table +{ +public: + + using policy = typename std::conditional, crc_forward_policy>::type; + + using traits = typename policy::traits; + + + // update the given crc accumulator with the value + [[nodiscard]] static constexpr TAccumulator update(TAccumulator crc, uint8_t value) + { + if constexpr (Table_Size == size_t::tiny) { + return policy::update_impl_tiny(crc, value, m_Table); + } + else if constexpr (Table_Size == size_t::small) { + return policy::update_impl_small(crc, value, m_Table); + } + else if constexpr (Table_Size == size_t::large) { + return policy::update_impl_large(crc, value, m_Table); + } + else { + static_assert("Unknown size_t"); + } + } + + // the crc accumulator initial value may need to be modified by the policy + // to account for rotation direction + [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) + { + return policy::make_initial_value(init); + } + +private: + +}; + + +// +// The generic CRC accumulator that is table driven +// +template +class crc +{ +public: + using algorithm = TAlgorithm; + using accumulator_type = typename algorithm::accumulator_type; + + // + // Update the accumulator with a new byte + // + void update(uint8_t value) + { + m_crc = table_impl::update(m_crc, value); + } + + // + // Extract the final value of the accumulator. + // + [[nodiscard]] accumulator_type final() { return m_crc ^ algorithm::xor_out_value; } + + // + // Reset the state of the accumulator back to the INITIAL value. + // + void reset() { m_crc = table_impl::make_initial_value(algorithm::initial_value); } + + +private: + using table_impl = crc_chunk_table; + + accumulator_type m_crc = table_impl::make_initial_value(algorithm::initial_value); +}; \ No newline at end of file diff --git a/include/etl/experimental/crc_table_256.h b/include/etl/experimental/crc_table_256.h new file mode 100644 index 00000000..bb6e45e8 --- /dev/null +++ b/include/etl/experimental/crc_table_256.h @@ -0,0 +1,519 @@ + +#pragma once + +#include +#include + +#include "../binary.h" +#include "../integral_limits.h" + +//***************************************************************************** +template +class entry +{ +private: + + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; + static ETL_CONSTANT bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1))) != 0U; + +public: + + static const TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); +}; + +//***************************************************************************** +/// 8 bit chunks +//***************************************************************************** +template +class table_entry_8 +{ +//private: +public: + + static const size_t Accumulator_Bits = entry::Accumulator_Bits; + static const size_t Shift_Bits = size_t(Accumulator_Bits - 8U); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value>::value>::value>::value>::value>::value>::value; +}; + +//***************************************************************************** +template +struct crc_table_256 +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[256] = + { + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value, + table_entry_8::value + }; + + return table; + } +}; +// +//// +//// Define the CRC algorithm parameters +//// +//template +//struct crc_algorithm +//{ +// using accumulator_type = TAccumulator; +// static constexpr TAccumulator polynomial = Polynomial; +// static constexpr TAccumulator initial_value = Initial; +// static constexpr TAccumulator xor_out_value = Xor_Out; +// static constexpr bool reverse = Reverse; +//}; +// +//// +//// Define the basic traits we use in our CRC accumulators and Table Lookup +//// +//template +//struct crc_traits {}; +// +//template +//struct crc_traits_256 +//{ +// static constexpr std::size_t ACCUMULATOR_BITS = etl::integral_limits::bits; +// static constexpr std::size_t CHUNK_BITS = 8; +// static constexpr uint8_t CHUNK_MASK = 0xFFu; +// static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; +// +// using table_type = std::array; +//}; +// +//// +//// CRC rotation policies. +//// +//// Forward rotation means that we clock in data MSB->LSB and rotate the Accumulator register left +//// Reverse rotation means that we clock in data LSB->MSB and rotate the Accumulator register right +//// +// +//template +//struct crc_forward_policy_256 +//{ +// typedef crc_traits_256 traits; +// +// ETL_NODISCARD static constexpr TAccumulator update_impl_256(TAccumulator crc, +// uint8_t value, +// typename traits::table_type const& table) +// { +// crc = update_chunk(crc, value, table); // full byte +// return crc; +// } +// +// ETL_NODISCARD static constexpr TAccumulator update_chunk(TAccumulator crc, +// uint8_t value, +// typename traits::table_type const& table) +// { +// value &= traits::CHUNK_MASK; +// +// // Extract the most significant nibble of the crc and xor with the value nibble +// uint8_t t = (crc >> (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS)) ^ value; +// +// // special case for when chunk size is same as accumulator size. +// if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { +// // shift crc left the size of the nibble +// crc <<= traits::CHUNK_BITS; +// +// // xor in the table data +// crc ^= table[t]; +// } +// else { +// crc = table[t]; +// } +// +// return crc; +// } +// +// ETL_NODISCARD static constexpr TAccumulator make_initial_value(TAccumulator init) +// { +// return init; +// } +//}; +// +//template +//struct crc_reverse_policy_256 +//{ +// typedef crc_traits_256 traits; +// +// ETL_NODISCARD static constexpr TAccumulator update_impl( +// TAccumulator crc, uint8_t value, typename traits::table_type const& table) +// { +// crc = update_chunk(crc, value, table); // full byte +// return crc; +// } +// +// ETL_NODISCARD static constexpr TAccumulator update_chunk( +// TAccumulator crc, uint8_t value, typename traits::table_type const& table) +// { +// // ensure we have only 4 bits +// value &= traits::CHUNK_MASK; +// +// // Extract the least significant nibble of the crc and xor with the value nibble +// uint8_t t = (crc & traits::CHUNK_MASK) ^ value; +// +// // special case for when chunk size is same as accumulator size. +// if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { +// // shit crc right the size of a nibble +// crc >>= traits::CHUNK_BITS; +// +// // xor in the table data +// crc ^= table[t]; +// } +// else { +// crc = table[t]; +// } +// +// return crc; +// } +// +// ETL_NODISCARD static constexpr TAccumulator make_initial_value(TAccumulator init) +// { +// return etl::reverse_bits(init); +// } +//}; +// +// +//// +//// A generic CRC lookup table sized for computing a nibble (4 bits) at a time. +//// +//// This is can be a large reduction of table space storage for embedded devices. +//// +//template ::value>> +//class crc_chunk_table +//{ +//public: +// +// using policy = typename std::conditional, crc_forward_policy>::type; +// +// using traits = typename policy::traits; +// +// +// // update the given crc accumulator with the value +// ETL_NODISCARD static constexpr TAccumulator update(TAccumulator crc, uint8_t value) +// { +// if constexpr (Table_Size == size_t::tiny) { +// return policy::update_impl_tiny(crc, value, m_Table); +// } +// else if constexpr (Table_Size == size_t::small) { +// return policy::update_impl_small(crc, value, m_Table); +// } +// else if constexpr (Table_Size == size_t::large) { +// return policy::update_impl_large(crc, value, m_Table); +// } +// else { +// static_assert("Unknown size_t"); +// } +// } +// +// // the crc accumulator initial value may need to be modified by the policy +// // to account for rotation direction +// ETL_NODISCARD static constexpr TAccumulator make_initial_value(TAccumulator init) +// { +// return policy::make_initial_value(init); +// } +// +//private: +// +//}; +// +// +//// +//// The generic CRC accumulator that is table driven +//// +//template +//class crc +//{ +//public: +// using algorithm = TAlgorithm; +// using accumulator_type = typename algorithm::accumulator_type; +// +// // +// // Update the accumulator with a new byte +// // +// void update(uint8_t value) +// { +// m_crc = table_impl::update(m_crc, value); +// } +// +// // +// // Extract the final value of the accumulator. +// // +// ETL_NODISCARD accumulator_type final() { return m_crc ^ algorithm::xor_out_value; } +// +// // +// // Reset the state of the accumulator back to the INITIAL value. +// // +// void reset() { m_crc = table_impl::make_initial_value(algorithm::initial_value); } +// +// +//private: +// using table_impl = crc_chunk_table; +// +// accumulator_type m_crc = table_impl::make_initial_value(algorithm::initial_value); +//}; \ No newline at end of file diff --git a/include/etl/experimental/crc_table_4.h b/include/etl/experimental/crc_table_4.h new file mode 100644 index 00000000..a44bed84 --- /dev/null +++ b/include/etl/experimental/crc_table_4.h @@ -0,0 +1,698 @@ + +#pragma once + +#include +#include + +//***************************************************************************** +template +class entry +{ +private: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1))) != 0U; + +public: + + static const TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); +}; + +//***************************************************************************** +/// 8 bit chunks +//***************************************************************************** +template +class table_entry_8 +{ +//private: +public: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const size_t Shift_Bits = size_t(Accumulator_Bits - 8U); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value>::value>::value>::value>::value>::value>::value; +}; + +//***************************************************************************** +/// 4 bit chunks +//***************************************************************************** +template +class table_entry_4 +{ +private: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_4_Bits); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value>::value>::value; +}; + +//***************************************************************************** +/// 2 bit chunks +//***************************************************************************** +template +class table_entry_2 +{ +private: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_2_Bits); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value; +}; + +//***************************************************************************** +template +struct crc_table +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[256] = + { + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value + }; + + return table; + } +}; + +template +struct crc_table +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[16] = + { + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value + }; + + return table; + } +}; + +template +struct crc_table +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[4] = + { + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value + }; + + return table; + } +}; + + +// +// Define the CRC algorithm parameters +// +template +struct crc_algorithm +{ + using accumulator_type = TAccumulator; + static constexpr TAccumulator polynomial = Polynomial; + static constexpr TAccumulator initial_value = Initial; + static constexpr TAccumulator xor_out_value = Xor_Out; + static constexpr bool reverse = Reverse; +}; + +// +// Define the basic traits we use in our CRC accumulators and Table Lookup +// +template +struct crc_traits {}; + +template +struct crc_traits +{ + static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; + static constexpr std::size_t CHUNK_BITS = 2; + static constexpr uint8_t CHUNK_MASK = 0x03u; + static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; + + using table_type = std::array; +}; + +template +struct crc_traits +{ + static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; + static constexpr std::size_t CHUNK_BITS = 4; + static constexpr uint8_t CHUNK_MASK = 0x0Fu; + static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; + + using table_type = std::array; +}; + +template +struct crc_traits +{ + static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; + static constexpr std::size_t CHUNK_BITS = 8; + static constexpr uint8_t CHUNK_MASK = 0xFFu; + static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; + + using table_type = std::array; +}; + +// +// CRC rotation policies. +// +// Forward rotation means that we clock in data MSB->LSB and rotate the Accumulator register left +// Reverse rotation means that we clock in data LSB->MSB and rotate the Accumulator register right +// + +template +struct crc_forward_policy +{ + using traits = crc_traits; + + + [[nodiscard]] static constexpr TAccumulator update_impl_tiny( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_small( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_large( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value, table); // full byte + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_chunk( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + // ensure we have only 4 bits + value &= traits::CHUNK_MASK; + + // Extract the most significant nibble of the crc and xor with the value nibble + uint8_t t = (crc >> (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS)) ^ value; + + // special case for when chunk size is same as accumulator size. + if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { + // shit crc left the size of the nibble + crc <<= traits::CHUNK_BITS; + + // xor in the table data + crc ^= table[t]; + } + else { + crc = table[t]; + } + + return crc; + } + + [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) + { + // initialise with the register in the upper bits + TAccumulator entry = TAccumulator(index) << (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS); + + for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) + { + // We are processing MSBs / rotating left so we need to check the high bit + if (entry & (TAccumulator(1u) << (traits::ACCUMULATOR_BITS - 1))) { + entry = (entry << 1) ^ polynomial; + } + else { + entry = (entry << 1); + } + } + + return entry; + } + + [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) + { + return init; + } +}; + +template +struct crc_reverse_policy +{ + using traits = crc_traits; + + + [[nodiscard]] static constexpr TAccumulator update_impl_tiny( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_small( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble + crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_large( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value, table); // full byte + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_chunk( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + // ensure we have only 4 bits + value &= traits::CHUNK_MASK; + + // Extract the least significant nibble of the crc and xor with the value nibble + uint8_t t = (crc & traits::CHUNK_MASK) ^ value; + + // special case for when chunk size is same as accumulator size. + if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { + // shit crc right the size of a nibble + crc >>= traits::CHUNK_BITS; + + // xor in the table data + crc ^= table[t]; + } + else { + crc = table[t]; + } + + return crc; + } + + [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) + { + // initialise with the register in the lower bits + TAccumulator entry = TAccumulator(index); + + for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) + { + // we are processing LSBs/rotating right + if (entry & 0x1u) { + entry = (entry >> 1) ^ util::reverse_bits(polynomial); + } + else { + entry = (entry >> 1); + } + } + + return entry; + } + + [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) + { + return util::reverse_bits(init); + } +}; + + +// +// A generic CRC lookup table sized for computing a nibble (4 bits) at a time. +// +// This is can be a large reduction of table space storage for embedded devices. +// +template ::value>> +class crc_chunk_table +{ +public: + + using policy = typename std::conditional, crc_forward_policy>::type; + + using traits = typename policy::traits; + + + // update the given crc accumulator with the value + [[nodiscard]] static constexpr TAccumulator update(TAccumulator crc, uint8_t value) + { + if constexpr (Table_Size == size_t::tiny) { + return policy::update_impl_tiny(crc, value, m_Table); + } + else if constexpr (Table_Size == size_t::small) { + return policy::update_impl_small(crc, value, m_Table); + } + else if constexpr (Table_Size == size_t::large) { + return policy::update_impl_large(crc, value, m_Table); + } + else { + static_assert("Unknown size_t"); + } + } + + // the crc accumulator initial value may need to be modified by the policy + // to account for rotation direction + [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) + { + return policy::make_initial_value(init); + } + +private: + +}; + + +// +// The generic CRC accumulator that is table driven +// +template +class crc +{ +public: + using algorithm = TAlgorithm; + using accumulator_type = typename algorithm::accumulator_type; + + // + // Update the accumulator with a new byte + // + void update(uint8_t value) + { + m_crc = table_impl::update(m_crc, value); + } + + // + // Extract the final value of the accumulator. + // + [[nodiscard]] accumulator_type final() { return m_crc ^ algorithm::xor_out_value; } + + // + // Reset the state of the accumulator back to the INITIAL value. + // + void reset() { m_crc = table_impl::make_initial_value(algorithm::initial_value); } + + +private: + using table_impl = crc_chunk_table; + + accumulator_type m_crc = table_impl::make_initial_value(algorithm::initial_value); +}; \ No newline at end of file diff --git a/include/etl/experimental/crc_table_generator.h b/include/etl/experimental/crc_table_generator.h new file mode 100644 index 00000000..0d5c514a --- /dev/null +++ b/include/etl/experimental/crc_table_generator.h @@ -0,0 +1,712 @@ + +#pragma once + +#include +#include + +enum +{ + Chunk_8_Bits = 8, + Chunk_4_Bits = 4, + Chunk_2_Bits = 2 +}; + +//***************************************************************************** +template +class entry +{ +private: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1U))) != 0U; + +public: + + static const TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); +}; + +//***************************************************************************** +template +class table_entry; + +//***************************************************************************** +/// 8 bit chunks +//***************************************************************************** +template +class table_entry +{ +//private: +public: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_8_Bits); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value>::value>::value>::value>::value>::value>::value; +}; + +//***************************************************************************** +/// 4 bit chunks +//***************************************************************************** +template +class table_entry +{ +private: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_4_Bits); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value>::value>::value; +}; + +//***************************************************************************** +/// 2 bit chunks +//***************************************************************************** +template +class table_entry +{ +private: + + static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; + static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_2_Bits); + static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); + +public: + + static const TAccumulator value = entry::value>::value; +}; + +//***************************************************************************** +template +struct crc_table; + +template +struct crc_table +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[256] = + { + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value + }; + + return table; + } +}; + +template +struct crc_table +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[16] = + { + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value + }; + + return table; + } +}; + +template +struct crc_table +{ + static const TAccumulator* get_table() + { + static const TAccumulator table[4] = + { + table_entry::value, + table_entry::value, + table_entry::value, + table_entry::value + }; + + return table; + } +}; + + +// +// Define the CRC algorithm parameters +// +template +struct crc_algorithm +{ + using accumulator_type = TAccumulator; + static constexpr TAccumulator polynomial = Polynomial; + static constexpr TAccumulator initial_value = Initial; + static constexpr TAccumulator xor_out_value = Xor_Out; + static constexpr bool reverse = Reverse; +}; + +// +// Define the basic traits we use in our CRC accumulators and Table Lookup +// +template +struct crc_traits {}; + +template +struct crc_traits +{ + static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; + static constexpr std::size_t CHUNK_BITS = 2; + static constexpr uint8_t CHUNK_MASK = 0x03u; + static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; + + using table_type = std::array; +}; + +template +struct crc_traits +{ + static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; + static constexpr std::size_t CHUNK_BITS = 4; + static constexpr uint8_t CHUNK_MASK = 0x0Fu; + static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; + + using table_type = std::array; +}; + +template +struct crc_traits +{ + static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; + static constexpr std::size_t CHUNK_BITS = 8; + static constexpr uint8_t CHUNK_MASK = 0xFFu; + static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; + + using table_type = std::array; +}; + +// +// CRC rotation policies. +// +// Forward rotation means that we clock in data MSB->LSB and rotate the Accumulator register left +// Reverse rotation means that we clock in data LSB->MSB and rotate the Accumulator register right +// + +template +struct crc_forward_policy +{ + using traits = crc_traits; + + + [[nodiscard]] static constexpr TAccumulator update_impl_tiny( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_small( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_large( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value, table); // full byte + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_chunk( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + // ensure we have only 4 bits + value &= traits::CHUNK_MASK; + + // Extract the most significant nibble of the crc and xor with the value nibble + uint8_t t = (crc >> (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS)) ^ value; + + // special case for when chunk size is same as accumulator size. + if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { + // shit crc left the size of the nibble + crc <<= traits::CHUNK_BITS; + + // xor in the table data + crc ^= table[t]; + } + else { + crc = table[t]; + } + + return crc; + } + + [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) + { + // initialise with the register in the upper bits + TAccumulator entry = TAccumulator(index) << (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS); + + for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) + { + // We are processing MSBs / rotating left so we need to check the high bit + if (entry & (TAccumulator(1u) << (traits::ACCUMULATOR_BITS - 1))) { + entry = (entry << 1) ^ polynomial; + } + else { + entry = (entry << 1); + } + } + + return entry; + } + + [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) + { + return init; + } +}; + +template +struct crc_reverse_policy +{ + using traits = crc_traits; + + + [[nodiscard]] static constexpr TAccumulator update_impl_tiny( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); + crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_small( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble + crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_impl_large( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + crc = update_chunk(crc, value, table); // full byte + return crc; + } + + [[nodiscard]] static constexpr TAccumulator update_chunk( + TAccumulator crc, uint8_t value, typename traits::table_type const& table) + { + // ensure we have only 4 bits + value &= traits::CHUNK_MASK; + + // Extract the least significant nibble of the crc and xor with the value nibble + uint8_t t = (crc & traits::CHUNK_MASK) ^ value; + + // special case for when chunk size is same as accumulator size. + if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { + // shit crc right the size of a nibble + crc >>= traits::CHUNK_BITS; + + // xor in the table data + crc ^= table[t]; + } + else { + crc = table[t]; + } + + return crc; + } + + [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) + { + // initialise with the register in the lower bits + TAccumulator entry = TAccumulator(index); + + for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) + { + // we are processing LSBs/rotating right + if (entry & 0x1u) { + entry = (entry >> 1) ^ util::reverse_bits(polynomial); + } + else { + entry = (entry >> 1); + } + } + + return entry; + } + + [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) + { + return util::reverse_bits(init); + } +}; + + +// +// A generic CRC lookup table sized for computing a nibble (4 bits) at a time. +// +// This is can be a large reduction of table space storage for embedded devices. +// +template ::value>> +class crc_chunk_table +{ +public: + + using policy = typename std::conditional, crc_forward_policy>::type; + + using traits = typename policy::traits; + + + // update the given crc accumulator with the value + [[nodiscard]] static constexpr TAccumulator update(TAccumulator crc, uint8_t value) + { + if constexpr (Table_Size == size_t::tiny) { + return policy::update_impl_tiny(crc, value, m_Table); + } + else if constexpr (Table_Size == size_t::small) { + return policy::update_impl_small(crc, value, m_Table); + } + else if constexpr (Table_Size == size_t::large) { + return policy::update_impl_large(crc, value, m_Table); + } + else { + static_assert("Unknown size_t"); + } + } + + // the crc accumulator initial value may need to be modified by the policy + // to account for rotation direction + [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) + { + return policy::make_initial_value(init); + } + +private: + +}; + + +// +// The generic CRC accumulator that is table driven +// +template +class crc +{ +public: + using algorithm = TAlgorithm; + using accumulator_type = typename algorithm::accumulator_type; + + // + // Update the accumulator with a new byte + // + void update(uint8_t value) + { + m_crc = table_impl::update(m_crc, value); + } + + // + // Extract the final value of the accumulator. + // + [[nodiscard]] accumulator_type final() { return m_crc ^ algorithm::xor_out_value; } + + // + // Reset the state of the accumulator back to the INITIAL value. + // + void reset() { m_crc = table_impl::make_initial_value(algorithm::initial_value); } + + +private: + using table_impl = crc_chunk_table; + + accumulator_type m_crc = table_impl::make_initial_value(algorithm::initial_value); +}; \ No newline at end of file diff --git a/test/test_crc_table16.cpp b/test/test_crc_table16.cpp new file mode 100644 index 00000000..da46a9e5 --- /dev/null +++ b/test/test_crc_table16.cpp @@ -0,0 +1,1259 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2014 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/experimental/crc8_ccitt.h" +#include "etl/experimental/crc8_rohc.h" +//#include "etl/experimental/crc16.h" +//#include "etl/crc16.h" +//#include "etl/crc16_ccitt.h" +//#include "etl/crc16_aug_ccitt.h" +//#include "etl/crc16_kermit.h" +//#include "etl/crc16_modbus.h" +//#include "etl/crc16_usb.h" +//#include "etl/crc16_xmodem.h" +//#include "etl/crc16_genibus.h" +//#include "etl/crc16_x25.h" +//#include "etl/crc32.h" +//#include "etl/crc32_c.h" +//#include "etl/crc32_bzip2.h" +//#include "etl/crc32_mpeg2.h" +//#include "etl/crc32_posix.h" +//#include "etl/crc64_ecma.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + ////************************************************************************* + //TEST(test_crc8_ccitt_constructor) + //{ + // std::string data("123456789"); + + // uint8_t crc = etl::crc::crc8_ccitt_t16(data.begin(), data.end()); + + // CHECK_EQUAL(0xF4, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_ccitt_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_ccitt_t16 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint8_t crc = crc_calculator; + + // CHECK_EQUAL(0xF4, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_ccitt_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_ccitt_t16 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint8_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xF4, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_ccitt_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_ccitt_t16 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint8_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xF4, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_ccitt_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); + // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(int(crc1), int(crc2)); + + // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(int(crc1), int(crc3)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_constructor) + //{ + // std::string data("123456789"); + + // uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); + + // CHECK_EQUAL(0xD0, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_rohc crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint8_t crc = crc_calculator; + + // CHECK_EQUAL(0xD0, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_rohc crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint8_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD0, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_rohc crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint8_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD0, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); + // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(int(crc1), int(crc2)); + + // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(int(crc1), int(crc3)); + //} + + ////************************************************************************* + //TEST(test_crc16) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc::crc16(data.begin(), data.end()); + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); + + // CHECK_EQUAL(0x29B1, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_ccitt crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x29B1, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_ccitt crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x29B1, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_ccitt crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x29B1, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_kermit crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_kermit crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_kermit crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_modbus crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_modbus crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_modbus crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_usb) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_usb(data.begin(), data.end()); + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_usb crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_usb crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_usb crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_xmodem crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_xmodem crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_xmodem crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_aug_ccitt crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_aug_ccitt crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_aug_ccitt crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_genibus crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_genibus crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_genibus crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_x25) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_x25(data.begin(), data.end()); + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_x25 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_x25 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_x25 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32(data.begin(), data.end()); + + // CHECK_EQUAL(0xCBF43926, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0xCBF43926, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xCBF43926, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xCBF43926, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_c) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_c(data.begin(), data.end()); + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_c crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_c crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_c crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_bzip2 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_bzip2 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_bzip2 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_posix) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_posix crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_posix crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_posix crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_mpeg2 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_mpeg2 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_mpeg2 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma) + //{ + // std::string data("123456789"); + + // uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); + + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma_add_values) + //{ + // std::string data("123456789"); + + // etl::crc64_ecma crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint64_t crc = crc_calculator; + + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma_add_range) + //{ + // std::string data("123456789"); + + // etl::crc64_ecma crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint64_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc64_ecma crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint64_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); + // uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + }; +} + diff --git a/test/test_crc_table256.cpp b/test/test_crc_table256.cpp new file mode 100644 index 00000000..31c0b68f --- /dev/null +++ b/test/test_crc_table256.cpp @@ -0,0 +1,1259 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/experimental/crc8_ccitt.h" +#include "etl/experimental/crc8_rohc.h" +#include "etl/experimental/crc16.h" +#include "etl/experimental/crc16_aug_ccitt.h" +#include "etl/experimental/crc16_ccitt.h" +#include "etl/experimental/crc16_kermit.h" +#include "etl/experimental/crc16_modbus.h" +#include "etl/experimental/crc16_usb.h" +#include "etl/experimental/crc16_genibus.h" +#include "etl/experimental/crc16_x25.h" +#include "etl/experimental/crc16_xmodem.h" +#include "etl/experimental/crc32.h" +#include "etl/experimental/crc64_ecma.h" + +//#include "etl/crc32_c.h" +//#include "etl/crc32_bzip2.h" +//#include "etl/crc32_mpeg2.h" +//#include "etl/crc32_posix.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + TEST(test_crc8_ccitt_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc::crc8_ccitt(data.begin(), data.end()); + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc::crc8_ccitt crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc::crc8_ccitt crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc8_ccitt crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc::crc8_ccitt(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc::crc8_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc::crc8_ccitt(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + TEST(test_crc8_rohc_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_values) + { + std::string data("123456789"); + + etl::crc::crc8_rohc crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_range) + { + std::string data("123456789"); + + etl::crc::crc8_rohc crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc8_rohc crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc::crc8_rohc(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc::crc8_rohc((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc::crc8_rohc(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + TEST(test_crc16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc::crc16(data.begin(), data.end()); + + CHECK_EQUAL(0xBB3D, crc); + } + + ////************************************************************************* + //TEST(test_crc16_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + //************************************************************************* + TEST(test_crc16_ccitt) + { + std::string data("123456789"); + + uint16_t crc = etl::crc::crc16_ccitt(data.begin(), data.end()); + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc::crc16_ccitt crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc::crc16_ccitt crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc16_ccitt crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc::crc16_ccitt(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc::crc16_ccitt(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_kermit) + { + std::string data("123456789"); + + uint16_t crc = etl::crc::crc16_kermit(data.begin(), data.end()); + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_values) + { + std::string data("123456789"); + + etl::crc::crc16_kermit crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range) + { + std::string data("123456789"); + + etl::crc::crc16_kermit crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc16_kermit crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc::crc16_kermit(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc::crc16_kermit(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_modbus) + { + std::string data("123456789"); + + uint16_t crc = etl::crc::crc16_modbus(data.begin(), data.end()); + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_values) + { + std::string data("123456789"); + + etl::crc::crc16_modbus crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range) + { + std::string data("123456789"); + + etl::crc::crc16_modbus crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc16_modbus crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc::crc16_modbus(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc::crc16_modbus(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_usb) + { + std::string data("123456789"); + + uint16_t crc = etl::crc::crc16_usb(data.begin(), data.end()); + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_values) + { + std::string data("123456789"); + + etl::crc::crc16_usb crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range) + { + std::string data("123456789"); + + etl::crc::crc16_usb crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc16_usb crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc::crc16_usb(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc::crc16_usb(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_xmodem) + { + std::string data("123456789"); + + uint16_t crc = etl::crc::crc16_xmodem(data.begin(), data.end()); + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_values) + { + std::string data("123456789"); + + etl::crc::crc16_xmodem crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range) + { + std::string data("123456789"); + + etl::crc::crc16_xmodem crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc16_xmodem crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc::crc16_xmodem(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc::crc16_xmodem(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt) + { + std::string data("123456789"); + + uint16_t crc = etl::crc::crc16_aug_ccitt(data.begin(), data.end()); + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc::crc16_aug_ccitt crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc::crc16_aug_ccitt crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc16_aug_ccitt crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc::crc16_aug_ccitt(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc::crc16_aug_ccitt(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_genibus) + { + std::string data("123456789"); + + uint16_t crc = etl::crc::crc16_genibus(data.begin(), data.end()); + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_values) + { + std::string data("123456789"); + + etl::crc::crc16_genibus crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range) + { + std::string data("123456789"); + + etl::crc::crc16_genibus crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc16_genibus crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc::crc16_genibus(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc::crc16_genibus(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_x25) + { + std::string data("123456789"); + + uint16_t crc = etl::crc::crc16_x25(data.begin(), data.end()); + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_values) + { + std::string data("123456789"); + + etl::crc::crc16_x25 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range) + { + std::string data("123456789"); + + etl::crc::crc16_x25 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc16_x25 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc::crc16_x25(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc::crc16_x25(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32) + { + std::string data("123456789"); + + uint32_t crc = etl::crc::crc32(data.begin(), data.end()); + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_values) + { + std::string data("123456789"); + + etl::crc::crc32 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range) + { + std::string data("123456789"); + + etl::crc::crc32 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc32 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc::crc32(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc::crc32(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + ////************************************************************************* + //TEST(test_crc32_c) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_c(data.begin(), data.end()); + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_c crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_c crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_c crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_bzip2 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_bzip2 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_bzip2 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_posix) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_posix crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_posix crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_posix crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_mpeg2 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_mpeg2 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_mpeg2 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + //************************************************************************* + TEST(test_crc64_ecma) + { + std::string data("123456789"); + + uint64_t crc = etl::crc::crc64_ecma(data.begin(), data.end()); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_values) + { + std::string data("123456789"); + + etl::crc::crc64_ecma crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint64_t crc = crc_calculator; + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range) + { + std::string data("123456789"); + + etl::crc::crc64_ecma crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc64_ecma crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint64_t crc1 = etl::crc::crc64_ecma(data1.begin(), data1.end()); + uint64_t crc2 = etl::crc::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint64_t crc3 = etl::crc::crc64_ecma(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc_table4.cpp b/test/test_crc_table4.cpp new file mode 100644 index 00000000..de65d3a2 --- /dev/null +++ b/test/test_crc_table4.cpp @@ -0,0 +1,1259 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2014 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/experimental/crc8_ccitt.h" +#include "etl/experimental/crc8_rohc.h" +//#include "etl/experimental/crc16.h" +//#include "etl/crc16.h" +//#include "etl/crc16_ccitt.h" +//#include "etl/crc16_aug_ccitt.h" +//#include "etl/crc16_kermit.h" +//#include "etl/crc16_modbus.h" +//#include "etl/crc16_usb.h" +//#include "etl/crc16_xmodem.h" +//#include "etl/crc16_genibus.h" +//#include "etl/crc16_x25.h" +//#include "etl/crc32.h" +//#include "etl/crc32_c.h" +//#include "etl/crc32_bzip2.h" +//#include "etl/crc32_mpeg2.h" +//#include "etl/crc32_posix.h" +//#include "etl/crc64_ecma.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + ////************************************************************************* + //TEST(test_crc8_ccitt_constructor) + //{ + // std::string data("123456789"); + + // uint8_t crc = etl::crc::crc8_ccitt_t4(data.begin(), data.end()); + + // CHECK_EQUAL(0xF4, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_ccitt_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_ccitt_t4 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint8_t crc = crc_calculator; + + // CHECK_EQUAL(0xF4, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_ccitt_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_ccitt_t4 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint8_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xF4, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_ccitt_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_ccitt_t4 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint8_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xF4, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_ccitt_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); + // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(int(crc1), int(crc2)); + + // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(int(crc1), int(crc3)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_constructor) + //{ + // std::string data("123456789"); + + // uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); + + // CHECK_EQUAL(0xD0, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_rohc crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint8_t crc = crc_calculator; + + // CHECK_EQUAL(0xD0, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_rohc crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint8_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD0, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc8_rohc crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint8_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD0, int(crc)); + //} + + ////************************************************************************* + //TEST(test_crc8_rohc_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); + // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(int(crc1), int(crc2)); + + // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(int(crc1), int(crc3)); + //} + + ////************************************************************************* + //TEST(test_crc16) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc::crc16(data.begin(), data.end()); + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xBB3D, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); + + // CHECK_EQUAL(0x29B1, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_ccitt crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x29B1, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_ccitt crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x29B1, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_ccitt crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x29B1, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_kermit crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_kermit crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_kermit crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_modbus crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_modbus crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_modbus crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_usb) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_usb(data.begin(), data.end()); + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_usb crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_usb crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_usb crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_xmodem crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_xmodem crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_xmodem crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_aug_ccitt crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_aug_ccitt crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_aug_ccitt crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_genibus crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_genibus crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_genibus crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_x25) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc16_x25(data.begin(), data.end()); + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_values) + //{ + // std::string data("123456789"); + + // etl::crc16_x25 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_range) + //{ + // std::string data("123456789"); + + // etl::crc16_x25 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc16_x25 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32(data.begin(), data.end()); + + // CHECK_EQUAL(0xCBF43926, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0xCBF43926, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xCBF43926, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xCBF43926, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_c) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_c(data.begin(), data.end()); + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_c crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_c crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_c crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE3069283, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_c_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_bzip2 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_bzip2 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_bzip2 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xFC891918, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_bzip2_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_posix) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_posix crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_posix crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_posix crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x765E7680, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_posix_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_values) + //{ + // std::string data("123456789"); + + // etl::crc32_mpeg2 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint32_t crc = crc_calculator; + + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_range) + //{ + // std::string data("123456789"); + + // etl::crc32_mpeg2 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc32_mpeg2 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint32_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x0376E6E7, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_mpeg2_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma) + //{ + // std::string data("123456789"); + + // uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); + + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma_add_values) + //{ + // std::string data("123456789"); + + // etl::crc64_ecma crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint64_t crc = crc_calculator; + + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma_add_range) + //{ + // std::string data("123456789"); + + // etl::crc64_ecma crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint64_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc64_ecma crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint64_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + //} + + ////************************************************************************* + //TEST(test_crc64_ecma_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); + // uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + }; +} + diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 35a7056c..05687816 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1272,6 +1272,21 @@ + + + + + + + + + + + + + + + @@ -3778,6 +3793,9 @@ + + + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index e37ddcd2..feb6f6c8 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -106,6 +106,9 @@ {562466b5-677d-4448-9e9e-f70805cd71ad} + + {016bd5a6-e277-4aba-8b28-28a9f1348473} + @@ -984,6 +987,51 @@ Source Files\Sanity Checks\C++17 + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + @@ -2102,6 +2150,15 @@ Source Files\Sanity Checks + + Source Files + + + Source Files + + + Source Files + From 33f3d2130027668aabd282483e36065d8699f63e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 24 Mar 2021 12:16:01 +0000 Subject: [PATCH 2/8] Intermediate commit --- include/etl/experimental/crc16.h | 14 +- include/etl/experimental/crc8_ccitt.h | 27 +- include/etl/experimental/crc8_rohc.h | 14 +- .../etl/experimental/crc_implementation_2.h | 650 +++++ include/etl/experimental/crc_parameters.h | 10 +- test/test_crc_table16.cpp | 2518 ++++++++--------- test/test_crc_table256.cpp | 1804 ++++++------ test/test_crc_table4.cpp | 2518 ++++++++--------- test/vs2019/etl.vcxproj | 9 +- test/vs2019/etl.vcxproj.filters | 3 + 10 files changed, 4115 insertions(+), 3452 deletions(-) create mode 100644 include/etl/experimental/crc_implementation_2.h diff --git a/include/etl/experimental/crc16.h b/include/etl/experimental/crc16.h index e09a1031..73c7246e 100644 --- a/include/etl/experimental/crc16.h +++ b/include/etl/experimental/crc16.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC16_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup crc16 16 bit CRC calculation ///\ingroup crc @@ -45,8 +42,12 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED template - class crc16_t : public etl::private_crc::crc_type + using crc16_t = etl::crc_type; +#else + template + class crc16_t : public etl::private_crc::crc_type { public: @@ -72,6 +73,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc16_t<256U> crc16_t256; typedef etl::crc::crc16_t<16U> crc16_t16; diff --git a/include/etl/experimental/crc8_ccitt.h b/include/etl/experimental/crc8_ccitt.h index 156944b4..4734ab52 100644 --- a/include/etl/experimental/crc8_ccitt.h +++ b/include/etl/experimental/crc8_ccitt.h @@ -32,21 +32,19 @@ SOFTWARE. #define ETL_CRC8_CCITT_EXP_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc8_ccitt 8 bit CRC calculation -///\ingroup crc +#include "crc_implementation_2.h" +#include "crc_parameters.h" namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED template - class crc8_ccitt_t : public etl::private_crc::crc_type + using crc8_ccitt_t = etl::crc_type; +#else + template + class crc8_ccitt_t : public etl::crc_type { public: @@ -72,11 +70,12 @@ namespace etl this->add(begin, end); } }; - - typedef etl::crc::crc8_ccitt_t<256U> crc8_ccitt_t256; - typedef etl::crc::crc8_ccitt_t<16U> crc8_ccitt_t16; - typedef etl::crc::crc8_ccitt_t<4U> crc8_ccitt_t4; - typedef crc8_ccitt_t256 crc8_ccitt; +#endif + + typedef crc8_ccitt_t<256U> crc8_ccitt_t256; + typedef crc8_ccitt_t<16U> crc8_ccitt_t16; + typedef crc8_ccitt_t<4U> crc8_ccitt_t4; + typedef crc8_ccitt_t256 crc8_ccitt; } } diff --git a/include/etl/experimental/crc8_rohc.h b/include/etl/experimental/crc8_rohc.h index baa4a3a0..b0e08d3a 100644 --- a/include/etl/experimental/crc8_rohc.h +++ b/include/etl/experimental/crc8_rohc.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC8_ROHC_EXP_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup rohc 8 bit CRC calculation ///\ingroup crc @@ -45,8 +42,12 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED template - class crc8_rohc_t : public etl::private_crc::crc_type + using crc8_rohc_t = etl::crc_type; +#else + template + class crc8_rohc_t : public etl::private_crc::crc_type { public: @@ -72,6 +73,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc8_rohc_t<256U> crc8_rohc_t256; typedef etl::crc::crc8_rohc_t<16U> crc8_rohc_t16; diff --git a/include/etl/experimental/crc_implementation_2.h b/include/etl/experimental/crc_implementation_2.h new file mode 100644 index 00000000..eaf60807 --- /dev/null +++ b/include/etl/experimental/crc_implementation_2.h @@ -0,0 +1,650 @@ + +#pragma once + +#include "../platform.h" +#include "../frame_check_sequence.h" +#include "../static_assert.h" +#include "../binary.h" + +#include "stdint.h" + +namespace etl +{ + namespace private_crc + { + //***************************************************************************** + /// CRC Traits + //***************************************************************************** + template + struct crc_traits; + + //********************************* + // Traits for table size of 4. + template <> + struct crc_traits<4U> + { + static ETL_CONSTANT uint8_t Chunk_Mask = 0x03U; + static ETL_CONSTANT size_t Chunk_Bits = 2U; + }; + + //********************************* + // Traits for table size of 16. + template <> + struct crc_traits<16U> + { + static ETL_CONSTANT uint8_t Chunk_Mask = 0x0FU; + static ETL_CONSTANT size_t Chunk_Bits = 4U; + }; + + //********************************* + // Traits for table size of 256. + template <> + struct crc_traits<256U> + { + static ETL_CONSTANT uint8_t Chunk_Mask = 0xFFU; + static ETL_CONSTANT size_t Chunk_Bits = 8U; + }; + + //***************************************************************************** + /// CRC Entry + //***************************************************************************** + template + class crc_entry + { + private: + + typename typedef TCrcParameters::accumulator_type accumulator_type; + + static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; + static ETL_CONSTANT accumulator_type Polynomial = TCrcParameters::Polynomial; + static ETL_CONSTANT bool Reflect = TCrcParameters::Reflect; + + static ETL_CONSTANT bool Do_Poly = Reflect ? (Entry & accumulator_type(1U)) != 0U + : (Entry & (accumulator_type(1U) << (Accumulator_Bits - 1U))) != 0U; + + public: + + static ETL_CONSTANT accumulator_type value = Reflect ? accumulator_type(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const::value : (Entry >> 1U)) + : accumulator_type(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); + }; + + //***************************************************************************** + /// CRC Table Entry + //***************************************************************************** + template + class crc_table_entry + { + ETL_STATIC_ASSERT((Chunk_Bits == 2U) || (Chunk_Bits == 4U) || (Chunk_Bits == 8U), "Chunk bits must be 2, 4 or 8"); + }; + + //********************************* + // Chunk bit size of 8. + template + class crc_table_entry + { + public: + + typedef typename TCrcParameters::accumulator_type accumulator_type; + + static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 8U); + static ETL_CONSTANT accumulator_type Entry = TCrcParameters::Reflect ? accumulator_type(Index) : accumulator_type(accumulator_type(Index) << Shift_Bits); + + static ETL_CONSTANT accumulator_type value = crc_entry::value>::value>::value>::value>::value>::value>::value>::value; + }; + + //********************************* + // Chunk bit size of 4. + template + class crc_table_entry + { + public: + + typedef typename TCrcParameters::accumulator_type accumulator_type; + + static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 4U); + static ETL_CONSTANT accumulator_type Entry = TCrcParameters::Reflect ? accumulator_type(Index) : accumulator_type(accumulator_type(Index) << Shift_Bits); + + static const accumulator_type value = crc_entry::value>::value>::value>::value; + }; + + //********************************* + // Chunk bit size of 2. + template + class crc_table_entry + { + public: + + typedef typename TCrcParameters::accumulator_type accumulator_type; + + static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 2U); + static ETL_CONSTANT accumulator_type Entry = TCrcParameters::Reflect ? accumulator_type(Index) : accumulator_type(accumulator_type(Index) << Shift_Bits); + + static const accumulator_type value = crc_entry::value>::value; + }; + + //************************************************************************* + // Accumulator_Bits > Chunk_Bits and not reflected + template + typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && !Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + + crc <<= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + // Accumulator_Bits > Chunk_Bits and reflected + template + typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + size_t index = (crc & Chunk_Mask) ^ value; + + crc >>= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + // Accumulator_Bits == Chunk_Bits and not reflected + template + typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && !Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + + crc = table[index]; + + return crc; + } + + //************************************************************************* + // Accumulator_Bits == Chunk_Bits and reflected + template + typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + size_t index = (crc & Chunk_Mask) ^ value; + + crc = table[index]; + + return crc; + } + + //***************************************************************************** + // + //***************************************************************************** + template + struct crc_policy; + + //********************************* + // Policy for 256 sized table. + template + struct crc_policy + { + typedef typename TCrcParameters::accumulator_type accumulator_type; + typedef accumulator_type value_type; + + static ETL_CONSTANT size_t Table_Size = 256U; + static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; + static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; + static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; + + //************************************************************************* + ETL_CONSTEXPR accumulator_type initial() const + { + return TCrcParameters::Initial; + } + + //************************************************************************* + accumulator_type add(accumulator_type crc, uint8_t value) const + { + static ETL_CONSTANT accumulator_type table[Table_Size] = + { + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value + }; + + crc = crc_update_chunk(crc, value, table); + + return crc; + } + + //************************************************************************* + accumulator_type final(accumulator_type crc) const + { + return crc ^ TCrcParameters::Xor_Out; + } + }; + + //********************************* + // Policy for 16 sized table. + template + struct crc_policy + { + typedef typename TCrcParameters::accumulator_type accumulator_type; + typedef accumulator_type value_type; + + static ETL_CONSTANT size_t Table_Size = 16U; + static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; + static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; + static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; + + typedef accumulator_type value_type; + + //************************************************************************* + ETL_CONSTEXPR accumulator_type initial() const + { + return TCrcParameters::Initial; + } + + //************************************************************************* + static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) + { + // Extract the most significant nibble of the crc and xor with the value nibble. + size_t index = (crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value; + + crc <<= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + accumulator_type add(accumulator_type crc, uint8_t value) const + { + static ETL_CONSTANT accumulator_type table[Table_Size] = + { + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value + }; + + crc = update_chunk(crc, (value >> Chunk_Bits) & Chunk_Mask, table); + crc = update_chunk(crc, value & Chunk_Mask, table); + + return crc; + } + + //************************************************************************* + accumulator_type final(accumulator_type crc) const + { + return crc ^ TCrcParameters::Xor_Out; + } + }; + + //********************************* + // Policy for 4 sized table. + template + struct crc_policy + { + typedef typename TCrcParameters::accumulator_type accumulator_type; + typedef accumulator_type value_type; + + static ETL_CONSTANT size_t Table_Size = 4U; + static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; + static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; + static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; + + //************************************************************************* + ETL_CONSTEXPR accumulator_type initial() const + { + return TCrcParameters::Initial; + } + + //************************************************************************* + static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) + { + // Extract the most significant nibble of the crc and xor with the value nibble. + size_t index = (crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value; + + crc <<= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //************************************************************************* + accumulator_type add(accumulator_type crc, uint8_t value) const + { + static ETL_CONSTANT accumulator_type table[Table_Size] = + { + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value + }; + + crc = update_chunk(crc, (value >> (Chunk_Bits * 3U)) & Chunk_Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Bits * 2U)) & Chunk_Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Bits * 1U)) & Chunk_Mask, table); + crc = update_chunk(crc, value & Chunk_Mask, table); + + return crc; + } + + //************************************************************************* + accumulator_type final(accumulator_type crc) const + { + return crc ^ TCrcParameters::Xor_Out; + } + }; + } + + //***************************************************************************** + /// Basic parameterised CRC type. + //***************************************************************************** + template + class crc_type : public etl::frame_check_sequence > + { + public: + + ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc_type() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc_type(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +} diff --git a/include/etl/experimental/crc_parameters.h b/include/etl/experimental/crc_parameters.h index 309dbdf4..a4551ee2 100644 --- a/include/etl/experimental/crc_parameters.h +++ b/include/etl/experimental/crc_parameters.h @@ -1,6 +1,7 @@ #pragma once #include "../platform.h" +#include "../integral_limits.h" namespace etl { @@ -10,10 +11,11 @@ namespace etl struct crc_parameters { typedef TAccumulator accumulator_type; - static ETL_CONSTANT TAccumulator Polynomial = Polynomial_; - static ETL_CONSTANT TAccumulator Initial = Initial_; - static ETL_CONSTANT TAccumulator Xor_Out = Xor_Out_; - static ETL_CONSTANT bool Reflect = Reflect_; + static ETL_CONSTANT TAccumulator Polynomial = Polynomial_; + static ETL_CONSTANT TAccumulator Initial = Initial_; + static ETL_CONSTANT TAccumulator Xor_Out = Xor_Out_; + static ETL_CONSTANT bool Reflect = Reflect_; + static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; }; // 8 bit. diff --git a/test/test_crc_table16.cpp b/test/test_crc_table16.cpp index da46a9e5..09fd98f2 100644 --- a/test/test_crc_table16.cpp +++ b/test/test_crc_table16.cpp @@ -1,1259 +1,1259 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2014 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include "unit_test_framework.h" - -#include -#include -#include -#include - -#include "etl/experimental/crc8_ccitt.h" -#include "etl/experimental/crc8_rohc.h" -//#include "etl/experimental/crc16.h" -//#include "etl/crc16.h" -//#include "etl/crc16_ccitt.h" -//#include "etl/crc16_aug_ccitt.h" -//#include "etl/crc16_kermit.h" -//#include "etl/crc16_modbus.h" -//#include "etl/crc16_usb.h" -//#include "etl/crc16_xmodem.h" -//#include "etl/crc16_genibus.h" -//#include "etl/crc16_x25.h" -//#include "etl/crc32.h" -//#include "etl/crc32_c.h" -//#include "etl/crc32_bzip2.h" -//#include "etl/crc32_mpeg2.h" -//#include "etl/crc32_posix.h" -//#include "etl/crc64_ecma.h" - -//***************************************************************************** -// The results for these tests were created from https://crccalc.com/ -//***************************************************************************** - -namespace -{ - SUITE(test_crc_experimental) - { - ////************************************************************************* - //TEST(test_crc8_ccitt_constructor) - //{ - // std::string data("123456789"); - - // uint8_t crc = etl::crc::crc8_ccitt_t16(data.begin(), data.end()); - - // CHECK_EQUAL(0xF4, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_ccitt_add_values) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_ccitt_t16 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint8_t crc = crc_calculator; - - // CHECK_EQUAL(0xF4, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_ccitt_add_range) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_ccitt_t16 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint8_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xF4, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_ccitt_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_ccitt_t16 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint8_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xF4, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_ccitt_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); - // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(int(crc1), int(crc2)); - - // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(int(crc1), int(crc3)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_constructor) - //{ - // std::string data("123456789"); - - // uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); - - // CHECK_EQUAL(0xD0, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_add_values) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_rohc crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint8_t crc = crc_calculator; - - // CHECK_EQUAL(0xD0, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_add_range) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_rohc crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint8_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xD0, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_rohc crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint8_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xD0, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); - // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(int(crc1), int(crc2)); - - // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(int(crc1), int(crc3)); - //} - - ////************************************************************************* - //TEST(test_crc16) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc::crc16(data.begin(), data.end()); - - // CHECK_EQUAL(0xBB3D, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_add_values) - //{ - // std::string data("123456789"); - - // etl::crc::crc16 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0xBB3D, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_add_range) - //{ - // std::string data("123456789"); - - // etl::crc::crc16 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xBB3D, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc::crc16 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xBB3D, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); - - // CHECK_EQUAL(0x29B1, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_ccitt crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x29B1, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_ccitt crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x29B1, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_ccitt crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x29B1, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); - - // CHECK_EQUAL(0x2189, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_kermit crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x2189, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_kermit crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x2189, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_kermit crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x2189, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); - - // CHECK_EQUAL(0x4B37, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_modbus crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x4B37, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_modbus crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x4B37, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_modbus crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x4B37, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_usb) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_usb(data.begin(), data.end()); - - // CHECK_EQUAL(0xB4C8, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_usb_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_usb crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0xB4C8, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_usb_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_usb crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xB4C8, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_usb_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_usb crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xB4C8, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_usb_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); - - // CHECK_EQUAL(0x31C3, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_xmodem crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x31C3, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_xmodem crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x31C3, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_xmodem crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x31C3, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); - - // CHECK_EQUAL(0xE5CC, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_aug_ccitt crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0xE5CC, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_aug_ccitt crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xE5CC, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_aug_ccitt crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xE5CC, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); - - // CHECK_EQUAL(0xD64E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_genibus crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0xD64E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_genibus crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xD64E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_genibus crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xD64E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_x25) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_x25(data.begin(), data.end()); - - // CHECK_EQUAL(0x906E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_x25_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_x25 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x906E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_x25_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_x25 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x906E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_x25_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_x25 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x906E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_x25_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32(data.begin(), data.end()); - - // CHECK_EQUAL(0xCBF43926, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0xCBF43926, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xCBF43926, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xCBF43926, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32_c) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_c(data.begin(), data.end()); - - // CHECK_EQUAL(0xE3069283, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_c_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_c crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0xE3069283, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_c_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_c crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xE3069283, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_c_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_c crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xE3069283, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_c_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); - - // CHECK_EQUAL(0xFC891918, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_bzip2 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0xFC891918, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_bzip2 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xFC891918, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_bzip2 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xFC891918, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32_posix) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_posix crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_posix crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_posix crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_mpeg2 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_mpeg2 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_mpeg2 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma) - //{ - // std::string data("123456789"); - - // uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); - - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma_add_values) - //{ - // std::string data("123456789"); - - // etl::crc64_ecma crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint64_t crc = crc_calculator; - - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma_add_range) - //{ - // std::string data("123456789"); - - // etl::crc64_ecma crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint64_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc64_ecma crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint64_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); - // uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - }; -} - +///****************************************************************************** +//The MIT License(MIT) +// +//Embedded Template Library. +//https://github.com/ETLCPP/etl +//https://www.etlcpp.com +// +//Copyright(c) 2014 jwellbelove +// +//Permission is hereby granted, free of charge, to any person obtaining a copy +//of this software and associated documentation files(the "Software"), to deal +//in the Software without restriction, including without limitation the rights +//to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +//copies of the Software, and to permit persons to whom the Software is +//furnished to do so, subject to the following conditions : +// +//The above copyright notice and this permission notice shall be included in all +//copies or substantial portions of the Software. +// +//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//SOFTWARE. +//******************************************************************************/ +// +//#include "unit_test_framework.h" +// +//#include +//#include +//#include +//#include +// +//#include "etl/experimental/crc8_ccitt.h" +//#include "etl/experimental/crc8_rohc.h" +////#include "etl/experimental/crc16.h" +////#include "etl/crc16.h" +////#include "etl/crc16_ccitt.h" +////#include "etl/crc16_aug_ccitt.h" +////#include "etl/crc16_kermit.h" +////#include "etl/crc16_modbus.h" +////#include "etl/crc16_usb.h" +////#include "etl/crc16_xmodem.h" +////#include "etl/crc16_genibus.h" +////#include "etl/crc16_x25.h" +////#include "etl/crc32.h" +////#include "etl/crc32_c.h" +////#include "etl/crc32_bzip2.h" +////#include "etl/crc32_mpeg2.h" +////#include "etl/crc32_posix.h" +////#include "etl/crc64_ecma.h" +// +////***************************************************************************** +//// The results for these tests were created from https://crccalc.com/ +////***************************************************************************** +// +//namespace +//{ +// SUITE(test_crc_experimental) +// { +// ////************************************************************************* +// //TEST(test_crc8_ccitt_constructor) +// //{ +// // std::string data("123456789"); +// +// // uint8_t crc = etl::crc::crc8_ccitt_t16(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xF4, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_ccitt_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_ccitt_t16 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint8_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xF4, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_ccitt_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_ccitt_t16 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint8_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xF4, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_ccitt_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_ccitt_t16 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint8_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xF4, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_ccitt_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); +// // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(int(crc1), int(crc2)); +// +// // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(int(crc1), int(crc3)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_constructor) +// //{ +// // std::string data("123456789"); +// +// // uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xD0, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_rohc crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint8_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xD0, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_rohc crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint8_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xD0, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_rohc crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint8_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xD0, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); +// // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(int(crc1), int(crc2)); +// +// // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(int(crc1), int(crc3)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc::crc16(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xBB3D, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc16 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xBB3D, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc16 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xBB3D, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc16 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xBB3D, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x29B1, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_ccitt crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x29B1, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_ccitt crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x29B1, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_ccitt crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x29B1, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x2189, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_kermit crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x2189, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_kermit crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x2189, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_kermit crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x2189, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x4B37, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_modbus crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x4B37, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_modbus crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x4B37, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_modbus crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x4B37, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_usb(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xB4C8, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_usb crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xB4C8, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_usb crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xB4C8, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_usb crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xB4C8, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x31C3, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_xmodem crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x31C3, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_xmodem crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x31C3, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_xmodem crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x31C3, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xE5CC, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_aug_ccitt crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xE5CC, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_aug_ccitt crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xE5CC, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_aug_ccitt crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xE5CC, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xD64E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_genibus crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xD64E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_genibus crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xD64E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_genibus crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xD64E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_x25(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x906E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_x25 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x906E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_x25 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x906E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_x25 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x906E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xCBF43926, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0xCBF43926, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xCBF43926, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xCBF43926, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32_c(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xE3069283, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_c crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0xE3069283, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_c crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xE3069283, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_c crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xE3069283, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xFC891918, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_bzip2 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0xFC891918, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_bzip2 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xFC891918, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_bzip2 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xFC891918, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x765E7680, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_posix crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0x765E7680, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_posix crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x765E7680, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_posix crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x765E7680, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x0376E6E7, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_mpeg2 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0x0376E6E7, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_mpeg2 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x0376E6E7, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_mpeg2 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x0376E6E7, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma) +// //{ +// // std::string data("123456789"); +// +// // uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc64_ecma crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint64_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc64_ecma crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint64_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc64_ecma crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint64_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); +// // uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// }; +//} +// diff --git a/test/test_crc_table256.cpp b/test/test_crc_table256.cpp index 31c0b68f..86af8870 100644 --- a/test/test_crc_table256.cpp +++ b/test/test_crc_table256.cpp @@ -36,16 +36,16 @@ SOFTWARE. #include "etl/experimental/crc8_ccitt.h" #include "etl/experimental/crc8_rohc.h" #include "etl/experimental/crc16.h" -#include "etl/experimental/crc16_aug_ccitt.h" -#include "etl/experimental/crc16_ccitt.h" -#include "etl/experimental/crc16_kermit.h" -#include "etl/experimental/crc16_modbus.h" -#include "etl/experimental/crc16_usb.h" -#include "etl/experimental/crc16_genibus.h" -#include "etl/experimental/crc16_x25.h" -#include "etl/experimental/crc16_xmodem.h" -#include "etl/experimental/crc32.h" -#include "etl/experimental/crc64_ecma.h" +//#include "etl/experimental/crc16_aug_ccitt.h" +//#include "etl/experimental/crc16_ccitt.h" +//#include "etl/experimental/crc16_kermit.h" +//#include "etl/experimental/crc16_modbus.h" +//#include "etl/experimental/crc16_usb.h" +//#include "etl/experimental/crc16_genibus.h" +//#include "etl/experimental/crc16_x25.h" +//#include "etl/experimental/crc16_xmodem.h" +//#include "etl/experimental/crc32.h" +//#include "etl/experimental/crc64_ecma.h" //#include "etl/crc32_c.h" //#include "etl/crc32_bzip2.h" @@ -210,12 +210,82 @@ namespace CHECK_EQUAL(0xBB3D, crc); } + //************************************************************************* + TEST(test_crc16_add_values) + { + std::string data("123456789"); + + etl::crc::crc16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range) + { + std::string data("123456789"); + + etl::crc::crc16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc::crc16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc::crc16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc::crc16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + ////************************************************************************* - //TEST(test_crc16_add_values) + //TEST(test_crc16_ccitt) //{ // std::string data("123456789"); - // etl::crc::crc16 crc_calculator; + // uint16_t crc = etl::crc::crc16_ccitt(data.begin(), data.end()); + + // CHECK_EQUAL(0x29B1, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_ccitt_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_ccitt crc_calculator; // for (size_t i = 0; i < data.size(); ++i) // { @@ -224,699 +294,558 @@ namespace // uint16_t crc = crc_calculator; - // CHECK_EQUAL(0xBB3D, crc); + // CHECK_EQUAL(0x29B1, crc); //} ////************************************************************************* - //TEST(test_crc16_add_range) + //TEST(test_crc16_ccitt_add_range) //{ // std::string data("123456789"); - // etl::crc::crc16 crc_calculator; + // etl::crc::crc16_ccitt crc_calculator; // crc_calculator.add(data.begin(), data.end()); // uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xBB3D, crc); + // CHECK_EQUAL(0x29B1, crc); //} ////************************************************************************* - //TEST(test_crc16_add_range_via_iterator) + //TEST(test_crc16_ccitt_add_range_via_iterator) //{ // std::string data("123456789"); - // etl::crc::crc16 crc_calculator; + // etl::crc::crc16_ccitt crc_calculator; // std::copy(data.begin(), data.end(), crc_calculator.input()); // uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xBB3D, crc); + // CHECK_EQUAL(0x29B1, crc); //} ////************************************************************************* - //TEST(test_crc16_add_range_endian) + //TEST(test_crc16_ccitt_add_range_endian) //{ // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; // std::vector data2 = { 0x04030201, 0x08070605 }; // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // uint16_t crc1 = etl::crc::crc16_ccitt(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); // CHECK_EQUAL(crc1, crc2); - // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); + // uint16_t crc3 = etl::crc::crc16_ccitt(data3.rbegin(), data3.rend()); // CHECK_EQUAL(crc1, crc3); //} - //************************************************************************* - TEST(test_crc16_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc::crc16_ccitt(data.begin(), data.end()); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc::crc16_ccitt crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc::crc16_ccitt crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc16_ccitt crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc::crc16_ccitt(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc::crc16_ccitt(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_kermit) - { - std::string data("123456789"); - - uint16_t crc = etl::crc::crc16_kermit(data.begin(), data.end()); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_values) - { - std::string data("123456789"); - - etl::crc::crc16_kermit crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range) - { - std::string data("123456789"); - - etl::crc::crc16_kermit crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc16_kermit crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc::crc16_kermit(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc::crc16_kermit(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_modbus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc::crc16_modbus(data.begin(), data.end()); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_values) - { - std::string data("123456789"); - - etl::crc::crc16_modbus crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range) - { - std::string data("123456789"); - - etl::crc::crc16_modbus crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc16_modbus crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc::crc16_modbus(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc::crc16_modbus(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_usb) - { - std::string data("123456789"); - - uint16_t crc = etl::crc::crc16_usb(data.begin(), data.end()); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_values) - { - std::string data("123456789"); - - etl::crc::crc16_usb crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range) - { - std::string data("123456789"); - - etl::crc::crc16_usb crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc16_usb crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc::crc16_usb(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc::crc16_usb(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_xmodem) - { - std::string data("123456789"); - - uint16_t crc = etl::crc::crc16_xmodem(data.begin(), data.end()); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_values) - { - std::string data("123456789"); - - etl::crc::crc16_xmodem crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range) - { - std::string data("123456789"); - - etl::crc::crc16_xmodem crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc16_xmodem crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc::crc16_xmodem(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc::crc16_xmodem(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc::crc16_aug_ccitt(data.begin(), data.end()); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc::crc16_aug_ccitt crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc::crc16_aug_ccitt crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc16_aug_ccitt crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc::crc16_aug_ccitt(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc::crc16_aug_ccitt(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_genibus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc::crc16_genibus(data.begin(), data.end()); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_values) - { - std::string data("123456789"); - - etl::crc::crc16_genibus crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range) - { - std::string data("123456789"); - - etl::crc::crc16_genibus crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc16_genibus crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc::crc16_genibus(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc::crc16_genibus(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_x25) - { - std::string data("123456789"); - - uint16_t crc = etl::crc::crc16_x25(data.begin(), data.end()); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_values) - { - std::string data("123456789"); - - etl::crc::crc16_x25 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range) - { - std::string data("123456789"); - - etl::crc::crc16_x25 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc16_x25 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc::crc16_x25(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc::crc16_x25(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32) - { - std::string data("123456789"); - - uint32_t crc = etl::crc::crc32(data.begin(), data.end()); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_values) - { - std::string data("123456789"); - - etl::crc::crc32 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range) - { - std::string data("123456789"); - - etl::crc::crc32 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc32 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc::crc32(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc::crc32(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - ////************************************************************************* - //TEST(test_crc32_c) + //TEST(test_crc16_kermit) //{ // std::string data("123456789"); - // uint32_t crc = etl::crc32_c(data.begin(), data.end()); + // uint16_t crc = etl::crc::crc16_kermit(data.begin(), data.end()); - // CHECK_EQUAL(0xE3069283, crc); + // CHECK_EQUAL(0x2189, crc); //} ////************************************************************************* - //TEST(test_crc32_c_add_values) + //TEST(test_crc16_kermit_add_values) //{ // std::string data("123456789"); - // etl::crc32_c crc_calculator; + // etl::crc::crc16_kermit crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_kermit crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_kermit crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x2189, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_kermit_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc::crc16_kermit(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc::crc16_kermit(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc::crc16_modbus(data.begin(), data.end()); + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_modbus crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_modbus crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_modbus crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x4B37, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_modbus_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc::crc16_modbus(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc::crc16_modbus(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_usb) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc::crc16_usb(data.begin(), data.end()); + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_usb crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_usb crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_usb crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xB4C8, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_usb_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc::crc16_usb(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc::crc16_usb(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc::crc16_xmodem(data.begin(), data.end()); + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_xmodem crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_xmodem crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_xmodem crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x31C3, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_xmodem_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc::crc16_xmodem(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc::crc16_xmodem(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc::crc16_aug_ccitt(data.begin(), data.end()); + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_aug_ccitt crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_aug_ccitt crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_aug_ccitt crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xE5CC, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_aug_ccitt_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc::crc16_aug_ccitt(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc::crc16_aug_ccitt(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc::crc16_genibus(data.begin(), data.end()); + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_genibus crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_genibus crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_genibus crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0xD64E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_genibus_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc::crc16_genibus(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc::crc16_genibus(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc16_x25) + //{ + // std::string data("123456789"); + + // uint16_t crc = etl::crc::crc16_x25(data.begin(), data.end()); + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_x25 crc_calculator; + + // for (size_t i = 0; i < data.size(); ++i) + // { + // crc_calculator.add(data[i]); + // } + + // uint16_t crc = crc_calculator; + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_range) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_x25 crc_calculator; + + // crc_calculator.add(data.begin(), data.end()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_range_via_iterator) + //{ + // std::string data("123456789"); + + // etl::crc::crc16_x25 crc_calculator; + + // std::copy(data.begin(), data.end(), crc_calculator.input()); + + // uint16_t crc = crc_calculator.value(); + + // CHECK_EQUAL(0x906E, crc); + //} + + ////************************************************************************* + //TEST(test_crc16_x25_add_range_endian) + //{ + // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + // std::vector data2 = { 0x04030201, 0x08070605 }; + // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + // uint16_t crc1 = etl::crc::crc16_x25(data1.begin(), data1.end()); + // uint16_t crc2 = etl::crc::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // CHECK_EQUAL(crc1, crc2); + + // uint16_t crc3 = etl::crc::crc16_x25(data3.rbegin(), data3.rend()); + // CHECK_EQUAL(crc1, crc3); + //} + + ////************************************************************************* + //TEST(test_crc32) + //{ + // std::string data("123456789"); + + // uint32_t crc = etl::crc::crc32(data.begin(), data.end()); + + // CHECK_EQUAL(0xCBF43926, crc); + //} + + ////************************************************************************* + //TEST(test_crc32_add_values) + //{ + // std::string data("123456789"); + + // etl::crc::crc32 crc_calculator; // for (size_t i = 0; i < data.size(); ++i) // { @@ -926,334 +855,405 @@ namespace // uint32_t crc = crc_calculator; - // CHECK_EQUAL(0xE3069283, crc); + // CHECK_EQUAL(0xCBF43926, crc); //} ////************************************************************************* - //TEST(test_crc32_c_add_range) + //TEST(test_crc32_add_range) //{ // std::string data("123456789"); - // etl::crc32_c crc_calculator; + // etl::crc::crc32 crc_calculator; // crc_calculator.add(data.begin(), data.end()); // uint32_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xE3069283, crc); + // CHECK_EQUAL(0xCBF43926, crc); //} ////************************************************************************* - //TEST(test_crc32_c_add_range_via_iterator) + //TEST(test_crc32_add_range_via_iterator) //{ // std::string data("123456789"); - // etl::crc32_c crc_calculator; + // etl::crc::crc32 crc_calculator; // std::copy(data.begin(), data.end(), crc_calculator.input()); // uint32_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xE3069283, crc); + // CHECK_EQUAL(0xCBF43926, crc); //} ////************************************************************************* - //TEST(test_crc32_c_add_range_endian) + //TEST(test_crc32_add_range_endian) //{ // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; // std::vector data2 = { 0x04030201, 0x08070605 }; // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // uint32_t crc1 = etl::crc::crc32(data1.begin(), data1.end()); + // uint32_t crc2 = etl::crc::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); // CHECK_EQUAL(crc1, crc2); - // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); + // uint32_t crc3 = etl::crc::crc32(data3.rbegin(), data3.rend()); // CHECK_EQUAL(crc1, crc3); //} + //////************************************************************************* + ////TEST(test_crc32_c) + ////{ + //// std::string data("123456789"); + + //// uint32_t crc = etl::crc32_c(data.begin(), data.end()); + + //// CHECK_EQUAL(0xE3069283, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_c_add_values) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_c crc_calculator; + + //// for (size_t i = 0; i < data.size(); ++i) + //// { + //// crc_calculator.add(data[i]); + //// } + + //// uint32_t crc = crc_calculator; + + + //// CHECK_EQUAL(0xE3069283, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_c_add_range) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_c crc_calculator; + + //// crc_calculator.add(data.begin(), data.end()); + + //// uint32_t crc = crc_calculator.value(); + + //// CHECK_EQUAL(0xE3069283, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_c_add_range_via_iterator) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_c crc_calculator; + + //// std::copy(data.begin(), data.end(), crc_calculator.input()); + + //// uint32_t crc = crc_calculator.value(); + + //// CHECK_EQUAL(0xE3069283, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_c_add_range_endian) + ////{ + //// std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + //// std::vector data2 = { 0x04030201, 0x08070605 }; + //// std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + //// uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); + //// uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + //// CHECK_EQUAL(crc1, crc2); + + //// uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); + //// CHECK_EQUAL(crc1, crc3); + ////} + + //////************************************************************************* + ////TEST(test_crc32_bzip2) + ////{ + //// std::string data("123456789"); + + //// uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); + + //// CHECK_EQUAL(0xFC891918, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_bzip2_add_values) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_bzip2 crc_calculator; + + //// for (size_t i = 0; i < data.size(); ++i) + //// { + //// crc_calculator.add(data[i]); + //// } + + //// uint32_t crc = crc_calculator; + + + //// CHECK_EQUAL(0xFC891918, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_bzip2_add_range) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_bzip2 crc_calculator; + + //// crc_calculator.add(data.begin(), data.end()); + + //// uint32_t crc = crc_calculator.value(); + + //// CHECK_EQUAL(0xFC891918, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_bzip2_add_range_via_iterator) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_bzip2 crc_calculator; + + //// std::copy(data.begin(), data.end(), crc_calculator.input()); + + //// uint32_t crc = crc_calculator.value(); + + //// CHECK_EQUAL(0xFC891918, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_bzip2_add_range_endian) + ////{ + //// std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + //// std::vector data2 = { 0x04030201, 0x08070605 }; + //// std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + //// uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); + //// uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + //// CHECK_EQUAL(crc1, crc2); + + //// uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); + //// CHECK_EQUAL(crc1, crc3); + ////} + + //////************************************************************************* + ////TEST(test_crc32_posix) + ////{ + //// std::string data("123456789"); + + //// uint32_t crc = etl::crc32_posix(data.begin(), data.end()); + + //// CHECK_EQUAL(0x765E7680, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_posix_add_values) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_posix crc_calculator; + + //// for (size_t i = 0; i < data.size(); ++i) + //// { + //// crc_calculator.add(data[i]); + //// } + + //// uint32_t crc = crc_calculator; + + + //// CHECK_EQUAL(0x765E7680, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_posix_add_range) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_posix crc_calculator; + + //// crc_calculator.add(data.begin(), data.end()); + + //// uint32_t crc = crc_calculator.value(); + + //// CHECK_EQUAL(0x765E7680, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_posix_add_range_via_iterator) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_posix crc_calculator; + + //// std::copy(data.begin(), data.end(), crc_calculator.input()); + + //// uint32_t crc = crc_calculator.value(); + + //// CHECK_EQUAL(0x765E7680, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_posix_add_range_endian) + ////{ + //// std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + //// std::vector data2 = { 0x04030201, 0x08070605 }; + //// std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + //// uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); + //// uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + //// CHECK_EQUAL(crc1, crc2); + + //// uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); + //// CHECK_EQUAL(crc1, crc3); + ////} + + //////************************************************************************* + ////TEST(test_crc32_mpeg2) + ////{ + //// std::string data("123456789"); + + //// uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); + + //// CHECK_EQUAL(0x0376E6E7, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_mpeg2_add_values) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_mpeg2 crc_calculator; + + //// for (size_t i = 0; i < data.size(); ++i) + //// { + //// crc_calculator.add(data[i]); + //// } + + //// uint32_t crc = crc_calculator; + + + //// CHECK_EQUAL(0x0376E6E7, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_mpeg2_add_range) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_mpeg2 crc_calculator; + + //// crc_calculator.add(data.begin(), data.end()); + + //// uint32_t crc = crc_calculator.value(); + + //// CHECK_EQUAL(0x0376E6E7, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_mpeg2_add_range_via_iterator) + ////{ + //// std::string data("123456789"); + + //// etl::crc32_mpeg2 crc_calculator; + + //// std::copy(data.begin(), data.end(), crc_calculator.input()); + + //// uint32_t crc = crc_calculator.value(); + + //// CHECK_EQUAL(0x0376E6E7, crc); + ////} + + //////************************************************************************* + ////TEST(test_crc32_mpeg2_add_range_endian) + ////{ + //// std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + //// std::vector data2 = { 0x04030201, 0x08070605 }; + //// std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + //// uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); + //// uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + //// CHECK_EQUAL(crc1, crc2); + + //// uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); + //// CHECK_EQUAL(crc1, crc3); + ////} + ////************************************************************************* - //TEST(test_crc32_bzip2) + //TEST(test_crc64_ecma) //{ // std::string data("123456789"); - // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); + // uint64_t crc = etl::crc::crc64_ecma(data.begin(), data.end()); - // CHECK_EQUAL(0xFC891918, crc); + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); //} ////************************************************************************* - //TEST(test_crc32_bzip2_add_values) + //TEST(test_crc64_ecma_add_values) //{ // std::string data("123456789"); - // etl::crc32_bzip2 crc_calculator; + // etl::crc::crc64_ecma crc_calculator; // for (size_t i = 0; i < data.size(); ++i) // { // crc_calculator.add(data[i]); // } - // uint32_t crc = crc_calculator; + // uint64_t crc = crc_calculator; - - // CHECK_EQUAL(0xFC891918, crc); + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); //} ////************************************************************************* - //TEST(test_crc32_bzip2_add_range) + //TEST(test_crc64_ecma_add_range) //{ // std::string data("123456789"); - // etl::crc32_bzip2 crc_calculator; + // etl::crc::crc64_ecma crc_calculator; // crc_calculator.add(data.begin(), data.end()); - // uint32_t crc = crc_calculator.value(); + // uint64_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xFC891918, crc); + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); //} ////************************************************************************* - //TEST(test_crc32_bzip2_add_range_via_iterator) + //TEST(test_crc64_ecma_add_range_via_iterator) //{ // std::string data("123456789"); - // etl::crc32_bzip2 crc_calculator; + // etl::crc::crc64_ecma crc_calculator; // std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint32_t crc = crc_calculator.value(); + // uint64_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xFC891918, crc); + // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); //} ////************************************************************************* - //TEST(test_crc32_bzip2_add_range_endian) + //TEST(test_crc64_ecma_add_range_endian) //{ // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; // std::vector data2 = { 0x04030201, 0x08070605 }; // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + // uint64_t crc1 = etl::crc::crc64_ecma(data1.begin(), data1.end()); + // uint64_t crc2 = etl::crc::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); // CHECK_EQUAL(crc1, crc2); - // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); + // uint64_t crc3 = etl::crc::crc64_ecma(data3.rbegin(), data3.rend()); // CHECK_EQUAL(crc1, crc3); //} - - ////************************************************************************* - //TEST(test_crc32_posix) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_posix crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_posix crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_posix crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_mpeg2 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_mpeg2 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_mpeg2 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - //************************************************************************* - TEST(test_crc64_ecma) - { - std::string data("123456789"); - - uint64_t crc = etl::crc::crc64_ecma(data.begin(), data.end()); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_values) - { - std::string data("123456789"); - - etl::crc::crc64_ecma crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint64_t crc = crc_calculator; - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range) - { - std::string data("123456789"); - - etl::crc::crc64_ecma crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc::crc64_ecma crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint64_t crc1 = etl::crc::crc64_ecma(data1.begin(), data1.end()); - uint64_t crc2 = etl::crc::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint64_t crc3 = etl::crc::crc64_ecma(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } }; } diff --git a/test/test_crc_table4.cpp b/test/test_crc_table4.cpp index de65d3a2..6b22fdf6 100644 --- a/test/test_crc_table4.cpp +++ b/test/test_crc_table4.cpp @@ -1,1259 +1,1259 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2014 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include "unit_test_framework.h" - -#include -#include -#include -#include - -#include "etl/experimental/crc8_ccitt.h" -#include "etl/experimental/crc8_rohc.h" -//#include "etl/experimental/crc16.h" -//#include "etl/crc16.h" -//#include "etl/crc16_ccitt.h" -//#include "etl/crc16_aug_ccitt.h" -//#include "etl/crc16_kermit.h" -//#include "etl/crc16_modbus.h" -//#include "etl/crc16_usb.h" -//#include "etl/crc16_xmodem.h" -//#include "etl/crc16_genibus.h" -//#include "etl/crc16_x25.h" -//#include "etl/crc32.h" -//#include "etl/crc32_c.h" -//#include "etl/crc32_bzip2.h" -//#include "etl/crc32_mpeg2.h" -//#include "etl/crc32_posix.h" -//#include "etl/crc64_ecma.h" - -//***************************************************************************** -// The results for these tests were created from https://crccalc.com/ -//***************************************************************************** - -namespace -{ - SUITE(test_crc_experimental) - { - ////************************************************************************* - //TEST(test_crc8_ccitt_constructor) - //{ - // std::string data("123456789"); - - // uint8_t crc = etl::crc::crc8_ccitt_t4(data.begin(), data.end()); - - // CHECK_EQUAL(0xF4, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_ccitt_add_values) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_ccitt_t4 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint8_t crc = crc_calculator; - - // CHECK_EQUAL(0xF4, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_ccitt_add_range) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_ccitt_t4 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint8_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xF4, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_ccitt_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_ccitt_t4 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint8_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xF4, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_ccitt_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); - // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(int(crc1), int(crc2)); - - // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(int(crc1), int(crc3)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_constructor) - //{ - // std::string data("123456789"); - - // uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); - - // CHECK_EQUAL(0xD0, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_add_values) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_rohc crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint8_t crc = crc_calculator; - - // CHECK_EQUAL(0xD0, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_add_range) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_rohc crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint8_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xD0, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc::crc8_rohc crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint8_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xD0, int(crc)); - //} - - ////************************************************************************* - //TEST(test_crc8_rohc_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); - // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(int(crc1), int(crc2)); - - // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(int(crc1), int(crc3)); - //} - - ////************************************************************************* - //TEST(test_crc16) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc::crc16(data.begin(), data.end()); - - // CHECK_EQUAL(0xBB3D, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_add_values) - //{ - // std::string data("123456789"); - - // etl::crc::crc16 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0xBB3D, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_add_range) - //{ - // std::string data("123456789"); - - // etl::crc::crc16 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xBB3D, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc::crc16 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xBB3D, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); - - // CHECK_EQUAL(0x29B1, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_ccitt crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x29B1, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_ccitt crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x29B1, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_ccitt crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x29B1, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_ccitt_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); - - // CHECK_EQUAL(0x2189, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_kermit crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x2189, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_kermit crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x2189, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_kermit crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x2189, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_kermit_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); - - // CHECK_EQUAL(0x4B37, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_modbus crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x4B37, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_modbus crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x4B37, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_modbus crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x4B37, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_modbus_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_usb) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_usb(data.begin(), data.end()); - - // CHECK_EQUAL(0xB4C8, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_usb_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_usb crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0xB4C8, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_usb_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_usb crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xB4C8, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_usb_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_usb crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xB4C8, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_usb_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); - - // CHECK_EQUAL(0x31C3, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_xmodem crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x31C3, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_xmodem crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x31C3, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_xmodem crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x31C3, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_xmodem_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); - - // CHECK_EQUAL(0xE5CC, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_aug_ccitt crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0xE5CC, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_aug_ccitt crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xE5CC, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_aug_ccitt crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xE5CC, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); - - // CHECK_EQUAL(0xD64E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_genibus crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0xD64E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_genibus crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xD64E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_genibus crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xD64E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_genibus_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc16_x25) - //{ - // std::string data("123456789"); - - // uint16_t crc = etl::crc16_x25(data.begin(), data.end()); - - // CHECK_EQUAL(0x906E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_x25_add_values) - //{ - // std::string data("123456789"); - - // etl::crc16_x25 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint16_t crc = crc_calculator; - - // CHECK_EQUAL(0x906E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_x25_add_range) - //{ - // std::string data("123456789"); - - // etl::crc16_x25 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x906E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_x25_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc16_x25 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint16_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x906E, crc); - //} - - ////************************************************************************* - //TEST(test_crc16_x25_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32(data.begin(), data.end()); - - // CHECK_EQUAL(0xCBF43926, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0xCBF43926, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xCBF43926, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xCBF43926, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32_c) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_c(data.begin(), data.end()); - - // CHECK_EQUAL(0xE3069283, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_c_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_c crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0xE3069283, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_c_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_c crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xE3069283, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_c_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_c crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xE3069283, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_c_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); - - // CHECK_EQUAL(0xFC891918, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_bzip2 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0xFC891918, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_bzip2 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xFC891918, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_bzip2 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0xFC891918, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_bzip2_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32_posix) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_posix crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_posix crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_posix crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x765E7680, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_posix_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2) - //{ - // std::string data("123456789"); - - // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_values) - //{ - // std::string data("123456789"); - - // etl::crc32_mpeg2 crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint32_t crc = crc_calculator; - - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_range) - //{ - // std::string data("123456789"); - - // etl::crc32_mpeg2 crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc32_mpeg2 crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint32_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x0376E6E7, crc); - //} - - ////************************************************************************* - //TEST(test_crc32_mpeg2_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma) - //{ - // std::string data("123456789"); - - // uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); - - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma_add_values) - //{ - // std::string data("123456789"); - - // etl::crc64_ecma crc_calculator; - - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } - - // uint64_t crc = crc_calculator; - - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma_add_range) - //{ - // std::string data("123456789"); - - // etl::crc64_ecma crc_calculator; - - // crc_calculator.add(data.begin(), data.end()); - - // uint64_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma_add_range_via_iterator) - //{ - // std::string data("123456789"); - - // etl::crc64_ecma crc_calculator; - - // std::copy(data.begin(), data.end(), crc_calculator.input()); - - // uint64_t crc = crc_calculator.value(); - - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} - - ////************************************************************************* - //TEST(test_crc64_ecma_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - // uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); - // uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); - - // uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} - }; -} - +///****************************************************************************** +//The MIT License(MIT) +// +//Embedded Template Library. +//https://github.com/ETLCPP/etl +//https://www.etlcpp.com +// +//Copyright(c) 2014 jwellbelove +// +//Permission is hereby granted, free of charge, to any person obtaining a copy +//of this software and associated documentation files(the "Software"), to deal +//in the Software without restriction, including without limitation the rights +//to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +//copies of the Software, and to permit persons to whom the Software is +//furnished to do so, subject to the following conditions : +// +//The above copyright notice and this permission notice shall be included in all +//copies or substantial portions of the Software. +// +//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//SOFTWARE. +//******************************************************************************/ +// +//#include "unit_test_framework.h" +// +//#include +//#include +//#include +//#include +// +//#include "etl/experimental/crc8_ccitt.h" +//#include "etl/experimental/crc8_rohc.h" +////#include "etl/experimental/crc16.h" +////#include "etl/crc16.h" +////#include "etl/crc16_ccitt.h" +////#include "etl/crc16_aug_ccitt.h" +////#include "etl/crc16_kermit.h" +////#include "etl/crc16_modbus.h" +////#include "etl/crc16_usb.h" +////#include "etl/crc16_xmodem.h" +////#include "etl/crc16_genibus.h" +////#include "etl/crc16_x25.h" +////#include "etl/crc32.h" +////#include "etl/crc32_c.h" +////#include "etl/crc32_bzip2.h" +////#include "etl/crc32_mpeg2.h" +////#include "etl/crc32_posix.h" +////#include "etl/crc64_ecma.h" +// +////***************************************************************************** +//// The results for these tests were created from https://crccalc.com/ +////***************************************************************************** +// +//namespace +//{ +// SUITE(test_crc_experimental) +// { +// ////************************************************************************* +// //TEST(test_crc8_ccitt_constructor) +// //{ +// // std::string data("123456789"); +// +// // uint8_t crc = etl::crc::crc8_ccitt_t4(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xF4, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_ccitt_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_ccitt_t4 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint8_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xF4, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_ccitt_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_ccitt_t4 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint8_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xF4, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_ccitt_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_ccitt_t4 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint8_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xF4, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_ccitt_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); +// // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(int(crc1), int(crc2)); +// +// // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(int(crc1), int(crc3)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_constructor) +// //{ +// // std::string data("123456789"); +// +// // uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xD0, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_rohc crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint8_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xD0, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_rohc crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint8_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xD0, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc8_rohc crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint8_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xD0, int(crc)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc8_rohc_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); +// // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(int(crc1), int(crc2)); +// +// // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(int(crc1), int(crc3)); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc::crc16(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xBB3D, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc16 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xBB3D, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc16 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xBB3D, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc::crc16 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xBB3D, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x29B1, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_ccitt crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x29B1, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_ccitt crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x29B1, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_ccitt crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x29B1, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_ccitt_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x2189, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_kermit crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x2189, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_kermit crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x2189, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_kermit crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x2189, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_kermit_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x4B37, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_modbus crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x4B37, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_modbus crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x4B37, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_modbus crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x4B37, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_modbus_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_usb(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xB4C8, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_usb crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xB4C8, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_usb crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xB4C8, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_usb crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xB4C8, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_usb_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x31C3, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_xmodem crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x31C3, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_xmodem crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x31C3, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_xmodem crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x31C3, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_xmodem_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xE5CC, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_aug_ccitt crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xE5CC, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_aug_ccitt crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xE5CC, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_aug_ccitt crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xE5CC, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_aug_ccitt_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xD64E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_genibus crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0xD64E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_genibus crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xD64E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_genibus crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xD64E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_genibus_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25) +// //{ +// // std::string data("123456789"); +// +// // uint16_t crc = etl::crc16_x25(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x906E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_x25 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint16_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x906E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_x25 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x906E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc16_x25 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint16_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x906E, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc16_x25_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); +// // uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xCBF43926, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0xCBF43926, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xCBF43926, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xCBF43926, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32_c(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xE3069283, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_c crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0xE3069283, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_c crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xE3069283, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_c crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xE3069283, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_c_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); +// +// // CHECK_EQUAL(0xFC891918, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_bzip2 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0xFC891918, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_bzip2 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xFC891918, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_bzip2 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0xFC891918, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_bzip2_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x765E7680, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_posix crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0x765E7680, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_posix crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x765E7680, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_posix crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x765E7680, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_posix_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2) +// //{ +// // std::string data("123456789"); +// +// // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x0376E6E7, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_mpeg2 crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint32_t crc = crc_calculator; +// +// +// // CHECK_EQUAL(0x0376E6E7, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_mpeg2 crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x0376E6E7, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc32_mpeg2 crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint32_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x0376E6E7, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc32_mpeg2_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); +// // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma) +// //{ +// // std::string data("123456789"); +// +// // uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); +// +// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma_add_values) +// //{ +// // std::string data("123456789"); +// +// // etl::crc64_ecma crc_calculator; +// +// // for (size_t i = 0; i < data.size(); ++i) +// // { +// // crc_calculator.add(data[i]); +// // } +// +// // uint64_t crc = crc_calculator; +// +// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma_add_range) +// //{ +// // std::string data("123456789"); +// +// // etl::crc64_ecma crc_calculator; +// +// // crc_calculator.add(data.begin(), data.end()); +// +// // uint64_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma_add_range_via_iterator) +// //{ +// // std::string data("123456789"); +// +// // etl::crc64_ecma crc_calculator; +// +// // std::copy(data.begin(), data.end(), crc_calculator.input()); +// +// // uint64_t crc = crc_calculator.value(); +// +// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); +// //} +// +// ////************************************************************************* +// //TEST(test_crc64_ecma_add_range_endian) +// //{ +// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +// // std::vector data2 = { 0x04030201, 0x08070605 }; +// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +// +// // uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); +// // uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); +// // CHECK_EQUAL(crc1, crc2); +// +// // uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); +// // CHECK_EQUAL(crc1, crc3); +// //} +// }; +//} +// diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 05687816..96f76a52 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1286,6 +1286,7 @@ + @@ -3793,9 +3794,13 @@ - + + false + - + + false + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index feb6f6c8..f27544ae 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1032,6 +1032,9 @@ ETL\Maths\Experimental + + ETL\Maths\Experimental + From a99473eb3f3dc4a0e5ae2ef019221ccc0810df47 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 24 Mar 2021 12:16:19 +0000 Subject: [PATCH 3/8] Intermediate commit --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 9c999a1f..35d9f0c7 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,3 @@ # These are supported funding model platforms -patreon: etlcpp +github: ETLCPP From 7e37fcf1960623619baa7bb717afdc011bdb0382 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 25 Mar 2021 10:22:55 +0000 Subject: [PATCH 4/8] Intermediate commit --- include/etl/experimental/crc16.h | 4 +- include/etl/experimental/crc16_aug_ccitt.h | 12 ++- include/etl/experimental/crc16_ccitt.h | 16 +-- include/etl/experimental/crc16_genibus.h | 16 +-- include/etl/experimental/crc16_kermit.h | 16 +-- include/etl/experimental/crc16_modbus.h | 18 ++-- include/etl/experimental/crc16_usb.h | 16 +-- include/etl/experimental/crc16_x25.h | 16 +-- include/etl/experimental/crc16_xmodem.h | 13 +-- include/etl/experimental/crc32.h | 16 +-- include/etl/experimental/crc32_bzip2.h | 82 +++++++++++++++ include/etl/experimental/crc32_c.h | 82 +++++++++++++++ include/etl/experimental/crc32_mpeg2.h | 82 +++++++++++++++ include/etl/experimental/crc32_posix.h | 82 +++++++++++++++ include/etl/experimental/crc64_ecma.h | 16 +-- include/etl/experimental/crc8_ccitt.h | 4 +- include/etl/experimental/crc8_rohc.h | 4 +- .../etl/experimental/crc_implementation_2.h | 8 +- include/etl/experimental/crc_parameters.h | 10 +- include/etl/integral_limits.h | 96 +++++++++--------- include/etl/integral_limits.zip | Bin 0 -> 1734 bytes test/test_crc_table256.cpp | 20 ++-- test/vs2019/etl.vcxproj | 5 +- test/vs2019/etl.vcxproj.filters | 15 ++- 24 files changed, 494 insertions(+), 155 deletions(-) create mode 100644 include/etl/experimental/crc32_bzip2.h create mode 100644 include/etl/experimental/crc32_c.h create mode 100644 include/etl/experimental/crc32_mpeg2.h create mode 100644 include/etl/experimental/crc32_posix.h create mode 100644 include/etl/integral_limits.zip diff --git a/include/etl/experimental/crc16.h b/include/etl/experimental/crc16.h index 73c7246e..68d921b4 100644 --- a/include/etl/experimental/crc16.h +++ b/include/etl/experimental/crc16.h @@ -42,7 +42,7 @@ namespace etl { namespace crc { -#if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 template using crc16_t = etl::crc_type; #else @@ -51,8 +51,6 @@ namespace etl { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* diff --git a/include/etl/experimental/crc16_aug_ccitt.h b/include/etl/experimental/crc16_aug_ccitt.h index 13b49212..8496ad70 100644 --- a/include/etl/experimental/crc16_aug_ccitt.h +++ b/include/etl/experimental/crc16_aug_ccitt.h @@ -32,7 +32,8 @@ SOFTWARE. #define ETL_CRC16_AUG_CCITT_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" +#include "crc_implementation_2.h" +#include "crc_parameters.h" #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 @@ -45,12 +46,16 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_aug_ccitt_t = etl::crc_type; +#else template - class crc16_aug_ccitt_t : public etl::private_crc::crc_type + class crc16_aug_ccitt_t : public etl::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); + //************************************************************************* /// Default constructor. @@ -72,6 +77,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc16_aug_ccitt_t<256U> crc16_aug_ccitt_t256; typedef etl::crc::crc16_aug_ccitt_t<16U> crc16_aug_ccitt_t16; diff --git a/include/etl/experimental/crc16_ccitt.h b/include/etl/experimental/crc16_ccitt.h index e2f12d31..0039f602 100644 --- a/include/etl/experimental/crc16_ccitt.h +++ b/include/etl/experimental/crc16_ccitt.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC16_CCITT_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup crc16_ccitt 16 bit CRC calculation ///\ingroup crc @@ -45,13 +42,15 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 template - class crc16_ccitt_t : public etl::private_crc::crc_type + using crc16_ccitt_t = etl::crc_type; +#else + template + class crc16_ccitt_t : public etl::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* @@ -72,6 +71,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc16_ccitt_t<256U> crc16_ccitt_t256; typedef etl::crc::crc16_ccitt_t<16U> crc16_ccitt_t16; diff --git a/include/etl/experimental/crc16_genibus.h b/include/etl/experimental/crc16_genibus.h index 72a5d1b7..d2707c55 100644 --- a/include/etl/experimental/crc16_genibus.h +++ b/include/etl/experimental/crc16_genibus.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC16_GENIBUS_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup crc16_genibus 16 bit CRC calculation ///\ingroup crc @@ -45,13 +42,15 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_genibus_t = etl::crc_type; +#else template - class crc16_genibus_t : public etl::private_crc::crc_type + class crc16_genibus_t : public etl::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* @@ -72,6 +71,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc16_genibus_t<256U> crc16_genibus_t256; typedef etl::crc::crc16_genibus_t<16U> crc16_genibus_t16; diff --git a/include/etl/experimental/crc16_kermit.h b/include/etl/experimental/crc16_kermit.h index dcb026ca..bcbbd85d 100644 --- a/include/etl/experimental/crc16_kermit.h +++ b/include/etl/experimental/crc16_kermit.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC16_KERMIT_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup crc16_kermit 16 bit CRC calculation ///\ingroup crc @@ -45,13 +42,15 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_kermit_t = etl::crc_type; +#else template - class crc16_kermit_t : public etl::private_crc::crc_type + class crc16_kermit_t : public etl::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* @@ -72,6 +71,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc16_kermit_t<256U> crc16_kermit_t256; typedef etl::crc::crc16_kermit_t<16U> crc16_kermit_t16; diff --git a/include/etl/experimental/crc16_modbus.h b/include/etl/experimental/crc16_modbus.h index cc62a179..94bdf574 100644 --- a/include/etl/experimental/crc16_modbus.h +++ b/include/etl/experimental/crc16_modbus.h @@ -32,26 +32,25 @@ SOFTWARE. #define ETL_CRC16_MODBUS_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" +#include "crc_implementation_2.h" +#include "crc_parameters.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_modbus 16 bit CRC calculation +//\defgroup crc16_modbus 16 bit CRC calculation ///\ingroup crc namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_modbus_t = etl::crc_type; +#else template - class crc16_modbus_t : public etl::private_crc::crc_type + class crc16_modbus_t : public etl::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* @@ -72,6 +71,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc16_modbus_t<256U> crc16_modbus_t256; typedef etl::crc::crc16_modbus_t<16U> crc16_modbus_t16; diff --git a/include/etl/experimental/crc16_usb.h b/include/etl/experimental/crc16_usb.h index e1205999..914a1a49 100644 --- a/include/etl/experimental/crc16_usb.h +++ b/include/etl/experimental/crc16_usb.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC16_USB_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup crc16_usb 16 bit CRC calculation ///\ingroup crc @@ -45,13 +42,15 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_usb_t = etl::crc_type; +#else template - class crc16_usb_t : public etl::private_crc::crc_type + class crc16_usb_t : public etl::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* @@ -72,6 +71,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc16_usb_t<256U> crc16_usb_t256; typedef etl::crc::crc16_usb_t<16U> crc16_usb_t16; diff --git a/include/etl/experimental/crc16_x25.h b/include/etl/experimental/crc16_x25.h index d423d342..33e34866 100644 --- a/include/etl/experimental/crc16_x25.h +++ b/include/etl/experimental/crc16_x25.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC16_X25_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup crc16_x25 16 bit CRC calculation ///\ingroup crc @@ -45,13 +42,15 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_x25_t = etl::crc_type; +#else template - class crc16_x25_t : public etl::private_crc::crc_type + class crc16_x25_t : public etl::private_crc::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* @@ -72,6 +71,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc16_x25_t<256U> crc16_x25_t256; typedef etl::crc::crc16_x25_t<16U> crc16_x25_t16; diff --git a/include/etl/experimental/crc16_xmodem.h b/include/etl/experimental/crc16_xmodem.h index c0d1921b..24ef637f 100644 --- a/include/etl/experimental/crc16_xmodem.h +++ b/include/etl/experimental/crc16_xmodem.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC16_XMODEM_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup crc16_xmodem 16 bit CRC calculation ///\ingroup crc @@ -47,15 +44,13 @@ namespace etl { #if ETL_CPP11_SUPPORTED template - using crc16_xmodem_t = etl::private_crc::crc_type; + using crc16_xmodem_t = etl::crc_type; #else template - class crc16_xmodem_t : public etl::private_crc::crc_type + class crc16_xmodem_t : public etl::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* diff --git a/include/etl/experimental/crc32.h b/include/etl/experimental/crc32.h index 5fd6b37e..c3bbf70a 100644 --- a/include/etl/experimental/crc32.h +++ b/include/etl/experimental/crc32.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC32_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup crc32 32 bit CRC calculation ///\ingroup crc @@ -45,13 +42,15 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED template - class crc32_t : public etl::private_crc::crc_type + using crc32_t = etl::crc_type; +#else + template + class crc32_t : public etl::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* @@ -72,6 +71,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc32_t<256U> crc32_t256; typedef etl::crc::crc32_t<16U> crc32_t16; diff --git a/include/etl/experimental/crc32_bzip2.h b/include/etl/experimental/crc32_bzip2.h new file mode 100644 index 00000000..5b04a078 --- /dev/null +++ b/include/etl/experimental/crc32_bzip2.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC32_BZIP2_EX_INCLUDED +#define ETL_CRC32_BZIP2_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation_2.h" +#include "crc_parameters.h" + +///\defgroup crc32_bzip2 32 bit CRC BZIP2 calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { +#if ETL_CPP11_SUPPORTED + template + using crc32_bzip2_t = etl::crc_type; +#else + template + class crc32_bzip2_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_bzip2_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_bzip2_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc::crc32_bzip2_t<256U> crc32_bzip2_t256; + typedef etl::crc::crc32_bzip2_t<16U> crc32_bzip2_t16; + typedef etl::crc::crc32_bzip2_t<4U> crc32_bzip2_t4; + typedef crc32_bzip2_t256 crc32_bzip2; + } +} +#endif diff --git a/include/etl/experimental/crc32_c.h b/include/etl/experimental/crc32_c.h new file mode 100644 index 00000000..f9df5c2a --- /dev/null +++ b/include/etl/experimental/crc32_c.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC32_C_EX_INCLUDED +#define ETL_CRC32_C_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation_2.h" +#include "crc_parameters.h" + +///\defgroup crc32_c 32 bit CRC_C calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { +#if ETL_CPP11_SUPPORTED + template + using crc32_c_t = etl::crc_type; +#else + template + class crc32_c_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_c_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_c_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc::crc32_c_t<256U> crc32_c_t256; + typedef etl::crc::crc32_c_t<16U> crc32_c_t16; + typedef etl::crc::crc32_c_t<4U> crc32_c_t4; + typedef crc32_c_t256 crc32_c; + } +} +#endif diff --git a/include/etl/experimental/crc32_mpeg2.h b/include/etl/experimental/crc32_mpeg2.h new file mode 100644 index 00000000..5b04a078 --- /dev/null +++ b/include/etl/experimental/crc32_mpeg2.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC32_BZIP2_EX_INCLUDED +#define ETL_CRC32_BZIP2_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation_2.h" +#include "crc_parameters.h" + +///\defgroup crc32_bzip2 32 bit CRC BZIP2 calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { +#if ETL_CPP11_SUPPORTED + template + using crc32_bzip2_t = etl::crc_type; +#else + template + class crc32_bzip2_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_bzip2_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_bzip2_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc::crc32_bzip2_t<256U> crc32_bzip2_t256; + typedef etl::crc::crc32_bzip2_t<16U> crc32_bzip2_t16; + typedef etl::crc::crc32_bzip2_t<4U> crc32_bzip2_t4; + typedef crc32_bzip2_t256 crc32_bzip2; + } +} +#endif diff --git a/include/etl/experimental/crc32_posix.h b/include/etl/experimental/crc32_posix.h new file mode 100644 index 00000000..bce4492e --- /dev/null +++ b/include/etl/experimental/crc32_posix.h @@ -0,0 +1,82 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC32_POSIX_EX_INCLUDED +#define ETL_CRC32_POSIX_EX_INCLUDED + +#include "../platform.h" +#include "crc_implementation_2.h" +#include "crc_parameters.h" + +///\defgroup crc32_posix 32 bit CRC POSIX calculation +///\ingroup crc + +namespace etl +{ + namespace crc + { +#if ETL_CPP11_SUPPORTED + template + using crc32_posix_t = etl::crc_type; +#else + template + class crc32_posix_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_posix_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_posix_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc::crc32_posix_t<256U> crc32_posix_t256; + typedef etl::crc::crc32_posix_t<16U> crc32_posix_t16; + typedef etl::crc::crc32_posix_t<4U> crc32_posix_t4; + typedef crc32_posix_t256 crc32_posix; + } +} +#endif diff --git a/include/etl/experimental/crc64_ecma.h b/include/etl/experimental/crc64_ecma.h index adb3980d..3a7aebe3 100644 --- a/include/etl/experimental/crc64_ecma.h +++ b/include/etl/experimental/crc64_ecma.h @@ -32,11 +32,8 @@ SOFTWARE. #define ETL_CRC64_ECMA_EX_INCLUDED #include "../platform.h" -#include "crc_implementation.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "crc_implementation_2.h" +#include "crc_parameters.h" ///\defgroup crc64_ecma 64 bit ECMA CRC calculation ///\ingroup crc @@ -45,13 +42,15 @@ namespace etl { namespace crc { +#if ETL_CPP11_SUPPORTED template - class crc64_ecma_t : public etl::private_crc::crc_type + using crc64_ecma_t = etl::crc_type; +#else + template + class crc64_ecma_t : public etl::crc_type { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* @@ -72,6 +71,7 @@ namespace etl this->add(begin, end); } }; +#endif typedef etl::crc::crc64_ecma_t<256U> crc64_ecma_t256; typedef etl::crc::crc64_ecma_t<16U> crc64_ecma_t16; diff --git a/include/etl/experimental/crc8_ccitt.h b/include/etl/experimental/crc8_ccitt.h index 4734ab52..4f6d8d2d 100644 --- a/include/etl/experimental/crc8_ccitt.h +++ b/include/etl/experimental/crc8_ccitt.h @@ -39,7 +39,7 @@ namespace etl { namespace crc { -#if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 template using crc8_ccitt_t = etl::crc_type; #else @@ -48,8 +48,6 @@ namespace etl { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* diff --git a/include/etl/experimental/crc8_rohc.h b/include/etl/experimental/crc8_rohc.h index b0e08d3a..d01d7e91 100644 --- a/include/etl/experimental/crc8_rohc.h +++ b/include/etl/experimental/crc8_rohc.h @@ -42,7 +42,7 @@ namespace etl { namespace crc { -#if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 template using crc8_rohc_t = etl::crc_type; #else @@ -51,8 +51,6 @@ namespace etl { public: - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - //************************************************************************* /// Default constructor. //************************************************************************* diff --git a/include/etl/experimental/crc_implementation_2.h b/include/etl/experimental/crc_implementation_2.h index eaf60807..b6945f0c 100644 --- a/include/etl/experimental/crc_implementation_2.h +++ b/include/etl/experimental/crc_implementation_2.h @@ -191,13 +191,13 @@ namespace etl } //***************************************************************************** - // + // CRC Policies. //***************************************************************************** template struct crc_policy; //********************************* - // Policy for 256 sized table. + // Policy for 256 entry table. template struct crc_policy { @@ -491,7 +491,7 @@ namespace etl }; //********************************* - // Policy for 16 sized table. + // Policy for 16 entry table. template struct crc_policy { @@ -560,7 +560,7 @@ namespace etl }; //********************************* - // Policy for 4 sized table. + // Policy for 4 entry table. template struct crc_policy { diff --git a/include/etl/experimental/crc_parameters.h b/include/etl/experimental/crc_parameters.h index a4551ee2..ffa4e8ca 100644 --- a/include/etl/experimental/crc_parameters.h +++ b/include/etl/experimental/crc_parameters.h @@ -31,13 +31,17 @@ namespace etl typedef crc_parameters crc16_modbus_parameters; typedef crc_parameters crc16_usb_parameters; typedef crc_parameters crc16_x25_parameters; - typedef crc_parameters crc16_xmodem_parameters; + typedef crc_parameters crc16_xmodem_parameters; // 32 bit. - typedef crc_parameters crc32_parameters; + typedef crc_parameters crc32_parameters; + typedef crc_parameters crc32_c_parameters; + typedef crc_parameters crc32_bzip2_parameters; + typedef crc_parameters crc32_mpeg2_parameters; + typedef crc_parameters crc32_posix_parameters; // 64 bit. - typedef crc_parameters crc64_ecma_parameters; + typedef crc_parameters crc64_ecma_parameters; } } diff --git a/include/etl/integral_limits.h b/include/etl/integral_limits.h index 7b8d4dd0..bfd54ce3 100644 --- a/include/etl/integral_limits.h +++ b/include/etl/integral_limits.h @@ -59,10 +59,10 @@ namespace etl template <> struct integral_limits { - static const int min = 0; - static const int max = 0; - static const int bits = 0; - static const bool is_signed = false; + static ETL_CONSTANT int min = 0; + static ETL_CONSTANT int max = 0; + static ETL_CONSTANT int bits = 0; + static ETL_CONSTANT bool is_signed = false; }; //*************************************************************************** @@ -71,10 +71,10 @@ namespace etl template <> struct integral_limits { - static const signed char min = SCHAR_MIN; - static const signed char max = SCHAR_MAX; - static const int bits = CHAR_BIT; - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT signed char min = SCHAR_MIN; + static ETL_CONSTANT signed char max = SCHAR_MAX; + static ETL_CONSTANT int bits = CHAR_BIT; + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; //*************************************************************************** @@ -83,10 +83,10 @@ namespace etl template <> struct integral_limits { - static const unsigned char min = 0; - static const unsigned char max = UCHAR_MAX; - static const int bits = CHAR_BIT; - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT unsigned char min = 0; + static ETL_CONSTANT unsigned char max = UCHAR_MAX; + static ETL_CONSTANT int bits = CHAR_BIT; + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; //*************************************************************************** @@ -95,10 +95,10 @@ namespace etl template <> struct integral_limits { - static const char min = (etl::is_signed::value) ? SCHAR_MIN : 0; - static const char max = (etl::is_signed::value) ? SCHAR_MAX : char(UCHAR_MAX); - static const int bits = CHAR_BIT; - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT char min = (etl::is_signed::value) ? SCHAR_MIN : 0; + static ETL_CONSTANT char max = (etl::is_signed::value) ? SCHAR_MAX : char(UCHAR_MAX); + static ETL_CONSTANT int bits = CHAR_BIT; + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; //*************************************************************************** @@ -107,10 +107,10 @@ namespace etl template <> struct integral_limits { - static const short min = SHRT_MIN; - static const short max = SHRT_MAX; - static const int bits = CHAR_BIT * (sizeof(short) / sizeof(char)); - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT short min = SHRT_MIN; + static ETL_CONSTANT short max = SHRT_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(short) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; //*************************************************************************** @@ -119,10 +119,10 @@ namespace etl template <> struct integral_limits { - static const unsigned short min = 0; - static const unsigned short max = USHRT_MAX; - static const int bits = CHAR_BIT * (sizeof(unsigned short) / sizeof(char)); - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT unsigned short min = 0; + static ETL_CONSTANT unsigned short max = USHRT_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned short) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; //*************************************************************************** @@ -131,10 +131,10 @@ namespace etl template <> struct integral_limits { - static const int min = INT_MIN; - static const int max = INT_MAX; - static const int bits = CHAR_BIT * (sizeof(int) / sizeof(char)); - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT int min = INT_MIN; + static ETL_CONSTANT int max = INT_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(int) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; //*************************************************************************** @@ -143,10 +143,10 @@ namespace etl template <> struct integral_limits { - static const unsigned int min = 0; - static const unsigned int max = UINT_MAX; - static const int bits = CHAR_BIT * (sizeof(unsigned int) / sizeof(char)); - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT unsigned int min = 0; + static ETL_CONSTANT unsigned int max = UINT_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned int) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; //*************************************************************************** @@ -155,10 +155,10 @@ namespace etl template <> struct integral_limits { - static const long min = LONG_MIN; - static const long max = LONG_MAX; - static const int bits = CHAR_BIT * (sizeof(long) / sizeof(char)); - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT long min = LONG_MIN; + static ETL_CONSTANT long max = LONG_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; //*************************************************************************** @@ -167,10 +167,10 @@ namespace etl template <> struct integral_limits { - static const unsigned long min = 0; - static const unsigned long max = ULONG_MAX; - static const int bits = CHAR_BIT * (sizeof(unsigned long) / sizeof(char)); - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT unsigned long min = 0; + static ETL_CONSTANT unsigned long max = ULONG_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; #ifndef LLONG_MAX @@ -191,10 +191,10 @@ namespace etl template <> struct integral_limits { - static const long long min = LLONG_MIN; - static const long long max = LLONG_MAX; - static const int bits = CHAR_BIT * (sizeof(long long) / sizeof(char)); - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT long long min = LLONG_MIN; + static ETL_CONSTANT long long max = LLONG_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long long) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; //*************************************************************************** @@ -203,10 +203,10 @@ namespace etl template <> struct integral_limits { - static const unsigned long long min = 0; - static const unsigned long long max = ULLONG_MAX; - static const int bits = CHAR_BIT * (sizeof(unsigned long long) / sizeof(char)); - static const bool is_signed = etl::is_signed::value; + static ETL_CONSTANT unsigned long long min = 0; + static ETL_CONSTANT unsigned long long max = ULLONG_MAX; + static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long long) / sizeof(char)); + static ETL_CONSTANT bool is_signed = etl::is_signed::value; }; } diff --git a/include/etl/integral_limits.zip b/include/etl/integral_limits.zip new file mode 100644 index 0000000000000000000000000000000000000000..1b22a9feb3fb6253c28ffa48926183f7c5ac5a15 GIT binary patch literal 1734 zcmV;%208gqO9KQH000080Ax#fQa3Oz_Cf{#00$xf01*HH0BLS?WoL3>Y+r0?ZE19K zE@FpHZ5(sa=;1J8XMWBX{1WX;4w_)n>^#tbk+a9XU1Fu z;nFnPO86!5_}sp8zWD}2wOak^(|{BU#X|MIiS-%i5My2|7DR#4SU4% zhzAY{lfdN!EqbY&J{%ScL(UUct5ye;53}B3KMt#^qu1N*D&fKG@n|$U#D#v62on*s z9w!ee9SnJ?Uxt&T<1_d+B0+8bt6u^3iv4@5c|*{ zy6J#afXCoQ50H?Qp+nr`E{$k302lh0s8~Q#KEyaI_W8(730iyLG8XqK0`kC%`&mdL z?sAb(w3wAR_T#`FI~Njvu`(LQ;UXG}HThW@VOk=cycqi?vwkCeE>?uS9|u7^68QRY zo+w9I`N<|5bBL%1% zKoX~U&PP}eWeH6cZ1dW=RV)=W8`_rnS!<{bI8bc7Kd8X1<}}TY1889>hI0qzH7Ld% z{G%C-3aDS&mTKEzTE&9aYU`Sci<(i_I}Odafh%-0Ox!9OZW4^@m>@EaV`-`_qP0}3 z-o#twO4Bvxu2L*qYmOnJUYiyu&{ix*t9Nw8f_BGho3@GtG%&8A8P^u3QCq6v9BKwG zf%+N$2fL~0x=2+lC>^Zd5*0$-Y~NYhP1AvCFo;gr<@LdBQx$876J0>5JDO<-Aa&DlEWE8CPRp74-fFg50mag6(UNP+Y#~I^ zQgkt86m&GyJd9{JEKCJW#C^wBrxBr{Dmn(Ug|kFCvBsfp60qH_s$j`q)Q>#k14>p` zGaU8CQuMBzsol+otv1jKO=v_mSczykap5E5sF(iX@YDRF-2F^0&MhAZMfKw}JRBa( zFY||lbb0DZmxD(xDZNM4s)jTQ-S6EbW5cmc_4ghMB4G6^LK&oSmf(Km1Qj^w=1?Br zOKapcBV6vu@oC|q3WNzNDsUPKNr>bYM)4WC9739=Vq?dl)N|}ytrnpaql`|{_*o=2 zx*Jd~jvP@Es*bEE;}lm>99{r=u@Jc-VTp^{BoDKHiv@t+nkEl8gR|7o7sxjm3w#t5 z6A;1qBp%@LlA*dks^NoZ#0!-1|G{1Z_Tzm_J^5VDTA1N+-IqHbwaj)<&4mxLHiGeW z2}d6`7`xxMH|`0>Z)4nx;{cE9E~A48_t+))Zor6i__<$08+Sl_6x=ksIa4{qOR({X zwz@6NSkvkSFC6C7OZl?>G|@{sU1`qtQ$;6~o?30XvH-SLyLW?ZFK3=bJ4}7Scs%!Y zTkDa%oOtIKCjN^vUorJXxO+VJZN@#F@?-|3N8OxnVj2FPX#mvL@?uJd9Rn+0FtB)5 znzE?8J&k^aLrVnOciylezAbJdjx?Gv2W7r#Ih)Rg+-E|HiO()NF&i+vh7zMcNbHwn z+%mq|kMG3*%j;OPi2->B_Lu@w4c&?hi`Kgw8Z$=Vsj)j7o@B&gf@e@8&+ya!-2_{3VBU5Yd6*CZ#bIX(Y*L2j zv0^U)lI2vpsgs@ro*r}Vw%?4G-edaz<=03Y{VkIL)+-ERhi3bw@9?yTe54It~ zg7GfWFl7U3!|p_QiVF+jpFs*(rw>mMWby^OK7lj)HhsGE>ix;d>FLGE(dpZF=Vuoe z=kJa#bR7*zAC94IJxwc~ywcib`f{aQyDk|DNLb3k>Mb zB*dalZNrRZkDcXkK@)eU$mH6rjL+rFEYmuTTuq{%>wn*ilgUqjV-@-jP)h*<6aW+e z000O8WJ`HcH!v>tLIwZ;2ODnA cb1rC5O9ci1000010096$0001S1^@s60Q4Ig&j0`b literal 0 HcmV?d00001 diff --git a/test/test_crc_table256.cpp b/test/test_crc_table256.cpp index 86af8870..352805a4 100644 --- a/test/test_crc_table256.cpp +++ b/test/test_crc_table256.cpp @@ -36,16 +36,16 @@ SOFTWARE. #include "etl/experimental/crc8_ccitt.h" #include "etl/experimental/crc8_rohc.h" #include "etl/experimental/crc16.h" -//#include "etl/experimental/crc16_aug_ccitt.h" -//#include "etl/experimental/crc16_ccitt.h" -//#include "etl/experimental/crc16_kermit.h" -//#include "etl/experimental/crc16_modbus.h" -//#include "etl/experimental/crc16_usb.h" -//#include "etl/experimental/crc16_genibus.h" -//#include "etl/experimental/crc16_x25.h" -//#include "etl/experimental/crc16_xmodem.h" -//#include "etl/experimental/crc32.h" -//#include "etl/experimental/crc64_ecma.h" +#include "etl/experimental/crc16_aug_ccitt.h" +#include "etl/experimental/crc16_ccitt.h" +#include "etl/experimental/crc16_kermit.h" +#include "etl/experimental/crc16_modbus.h" +#include "etl/experimental/crc16_usb.h" +#include "etl/experimental/crc16_genibus.h" +#include "etl/experimental/crc16_x25.h" +#include "etl/experimental/crc16_xmodem.h" +#include "etl/experimental/crc32.h" +#include "etl/experimental/crc64_ecma.h" //#include "etl/crc32_c.h" //#include "etl/crc32_bzip2.h" diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 96f76a52..41f6646b 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1273,7 +1273,6 @@ - @@ -1282,6 +1281,10 @@ + + + + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index f27544ae..43169276 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1002,9 +1002,6 @@ ETL\Maths\Experimental - - ETL\Maths\Experimental - ETL\Maths\Experimental @@ -1035,6 +1032,18 @@ ETL\Maths\Experimental + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + + + ETL\Maths\Experimental + From 696d3d8473f58122a462fbd44189bbb8afe70022 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 26 Mar 2021 15:53:30 +0000 Subject: [PATCH 5/8] Intermediate commit - Passing all tests --- include/etl/crc16.h | 45 +- include/etl/crc16_aug_ccitt.h | 49 +- include/etl/crc16_ccitt.h | 49 +- include/etl/crc16_genibus.h | 47 +- include/etl/crc16_kermit.h | 49 +- include/etl/crc16_modbus.h | 49 +- include/etl/crc16_usb.h | 49 +- include/etl/crc16_x25.h | 47 +- include/etl/crc16_xmodem.h | 47 +- include/etl/crc32.h | 45 +- include/etl/crc32_bzip2.h | 47 +- include/etl/crc32_c.h | 47 +- include/etl/crc32_mpeg2.h | 47 +- include/etl/crc32_posix.h | 47 +- include/etl/crc64_ecma.h | 47 +- include/etl/crc8_ccitt.h | 51 +- include/etl/crc8_rohc.h | 50 +- include/etl/experimental/crc.h | 82 - include/etl/experimental/crc16.h | 2 +- include/etl/experimental/crc16_aug_ccitt.h | 88 - include/etl/experimental/crc16_ccitt.h | 2 +- include/etl/experimental/crc16_genibus.h | 2 +- include/etl/experimental/crc16_kermit.h | 2 +- include/etl/experimental/crc16_modbus.h | 2 +- include/etl/experimental/crc16_usb.h | 2 +- include/etl/experimental/crc16_x25.h | 2 +- include/etl/experimental/crc16_xmodem.h | 2 +- include/etl/experimental/crc32.h | 2 +- include/etl/experimental/crc32_bzip2.h | 2 +- include/etl/experimental/crc32_c.h | 2 +- include/etl/experimental/crc32_mpeg2.h | 24 +- include/etl/experimental/crc32_posix.h | 2 +- include/etl/experimental/crc64_ecma.h | 2 +- include/etl/experimental/crc8_ccitt.h | 2 +- include/etl/experimental/crc8_rohc.h | 2 +- include/etl/experimental/crc8_table16.h | 234 -- include/etl/experimental/crc8_table256.h | 347 --- include/etl/experimental/crc8_table4.h | 212 -- include/etl/experimental/crc_implementation.h | 656 ----- include/etl/experimental/crc_table_16.h | 701 ----- include/etl/experimental/crc_table_256.h | 519 ---- include/etl/experimental/crc_table_4.h | 698 ----- .../etl/experimental/crc_table_generator.h | 712 ----- include/etl/private/crc16_poly_0x1021_.h | 191 -- include/etl/private/crc16_poly_0x8005.h | 191 -- include/etl/private/crc32_poly_0x04c11db7.h | 191 -- include/etl/private/crc32_poly_0x1edc6f41.h | 191 -- .../private/crc64_poly_0x42f0e1eba9ea3693.h | 223 -- include/etl/private/crc8_poly_0x07.h | 191 -- .../crc_implementation.h} | 306 +- .../crc_parameters.h | 26 + test/etl_profile.h | 1 + test/test_crc_table16.cpp | 2516 ++++++++--------- test/test_crc_table256.cpp | 1449 +++++----- test/test_crc_table4.cpp | 2516 ++++++++--------- test/vs2019/etl.vcxproj | 40 +- test/vs2019/etl.vcxproj.filters | 151 +- 57 files changed, 4193 insertions(+), 9105 deletions(-) delete mode 100644 include/etl/experimental/crc.h delete mode 100644 include/etl/experimental/crc16_aug_ccitt.h delete mode 100644 include/etl/experimental/crc8_table16.h delete mode 100644 include/etl/experimental/crc8_table256.h delete mode 100644 include/etl/experimental/crc8_table4.h delete mode 100644 include/etl/experimental/crc_implementation.h delete mode 100644 include/etl/experimental/crc_table_16.h delete mode 100644 include/etl/experimental/crc_table_256.h delete mode 100644 include/etl/experimental/crc_table_4.h delete mode 100644 include/etl/experimental/crc_table_generator.h delete mode 100644 include/etl/private/crc16_poly_0x1021_.h delete mode 100644 include/etl/private/crc16_poly_0x8005.h delete mode 100644 include/etl/private/crc32_poly_0x04c11db7.h delete mode 100644 include/etl/private/crc32_poly_0x1edc6f41.h delete mode 100644 include/etl/private/crc64_poly_0x42f0e1eba9ea3693.h delete mode 100644 include/etl/private/crc8_poly_0x07.h rename include/etl/{experimental/crc_implementation_2.h => private/crc_implementation.h} (78%) rename include/etl/{experimental => private}/crc_parameters.h (53%) diff --git a/include/etl/crc16.h b/include/etl/crc16.h index a742acd7..55e12a58 100644 --- a/include/etl/crc16.h +++ b/include/etl/crc16.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2014 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC16_INCLUDED #include "platform.h" -#include "private/crc16_poly_0x8005.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "private/crc_implementation.h" ///\defgroup crc16 16 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc16_poly_0x8005<0x0000U, 0x0000U, true> crc16; -} +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_t = etl::crc_type; +#else + template + class crc16_t : public etl::private_crc::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_t<256U> crc16_t256; + typedef etl::crc16_t<16U> crc16_t16; + typedef etl::crc16_t<4U> crc16_t4; + typedef crc16_t256 crc16; +} #endif diff --git a/include/etl/crc16_aug_ccitt.h b/include/etl/crc16_aug_ccitt.h index 6725b57d..4cd66e10 100644 --- a/include/etl/crc16_aug_ccitt.h +++ b/include/etl/crc16_aug_ccitt.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2019 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,49 @@ SOFTWARE. #define ETL_CRC16_AUG_CCITT_INCLUDED #include "platform.h" -#include "private/crc16_poly_0x1021_.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_aug_ccitt 16 bit CRC AUG CCITT calculation +///\defgroup crc16_aug_ccitt 16 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc16_poly_0x1021<0x1D0FU, 0x0000U, false> crc16_aug_ccitt; -} +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_aug_ccitt_t = etl::crc_type; +#else + template + class crc16_aug_ccitt_t : public etl::crc_type + { + public: + + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_aug_ccitt_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_aug_ccitt_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_aug_ccitt_t<256U> crc16_aug_ccitt_t256; + typedef etl::crc16_aug_ccitt_t<16U> crc16_aug_ccitt_t16; + typedef etl::crc16_aug_ccitt_t<4U> crc16_aug_ccitt_t4; + typedef crc16_aug_ccitt_t256 crc16_aug_ccitt; +} #endif diff --git a/include/etl/crc16_ccitt.h b/include/etl/crc16_ccitt.h index 66d1638f..eefd8255 100644 --- a/include/etl/crc16_ccitt.h +++ b/include/etl/crc16_ccitt.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2014 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -31,21 +31,48 @@ SOFTWARE. #ifndef ETL_CRC16_CCITT_INCLUDED #define ETL_CRC16_CCITT_INCLUDED -#include - #include "platform.h" -#include "private/crc16_poly_0x1021_.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_ccitt 16 bit CRC CCITT calculation +///\defgroup crc16_ccitt 16 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc16_poly_0x1021<0xFFFFU, 0x0000U, false> crc16_ccitt; -} +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_ccitt_t = etl::crc_type; +#else + template + class crc16_ccitt_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_ccitt_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_ccitt_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_ccitt_t<256U> crc16_ccitt_t256; + typedef etl::crc16_ccitt_t<16U> crc16_ccitt_t16; + typedef etl::crc16_ccitt_t<4U> crc16_ccitt_t4; + typedef crc16_ccitt_t256 crc16_ccitt; +} #endif diff --git a/include/etl/crc16_genibus.h b/include/etl/crc16_genibus.h index 876c0246..378eebc1 100644 --- a/include/etl/crc16_genibus.h +++ b/include/etl/crc16_genibus.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2019 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC16_GENIBUS_INCLUDED #include "platform.h" -#include "private/crc16_poly_0x1021_.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_aug_ccitt 16 bit CRC GENIBUS calculation +///\defgroup crc16_genibus 16 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc16_poly_0x1021<0xFFFFU, 0xFFFFU, false> crc16_genibus; -} +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_genibus_t = etl::crc_type; +#else + template + class crc16_genibus_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_genibus_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_genibus_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_genibus_t<256U> crc16_genibus_t256; + typedef etl::crc16_genibus_t<16U> crc16_genibus_t16; + typedef etl::crc16_genibus_t<4U> crc16_genibus_t4; + typedef crc16_genibus_t256 crc16_genibus; +} #endif diff --git a/include/etl/crc16_kermit.h b/include/etl/crc16_kermit.h index cdf878b2..fa7db6b1 100644 --- a/include/etl/crc16_kermit.h +++ b/include/etl/crc16_kermit.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2014 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -31,21 +31,48 @@ SOFTWARE. #ifndef ETL_CRC16_KERMIT_INCLUDED #define ETL_CRC16_KERMIT_INCLUDED -#include - #include "platform.h" -#include "private/crc16_poly_0x1021_.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_kermit 16 bit CRC Kermit calculation +///\defgroup crc16_kermit 16 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc16_poly_0x1021<0x0000U, 0x0000U, true> crc16_kermit; -} +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_kermit_t = etl::crc_type; +#else + template + class crc16_kermit_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_kermit_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_kermit_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_kermit_t<256U> crc16_kermit_t256; + typedef etl::crc16_kermit_t<16U> crc16_kermit_t16; + typedef etl::crc16_kermit_t<4U> crc16_kermit_t4; + typedef crc16_kermit_t256 crc16_kermit; +} #endif diff --git a/include/etl/crc16_modbus.h b/include/etl/crc16_modbus.h index e61d339a..aa536027 100644 --- a/include/etl/crc16_modbus.h +++ b/include/etl/crc16_modbus.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2018 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -31,21 +31,48 @@ SOFTWARE. #ifndef ETL_CRC16_MODBUS_INCLUDED #define ETL_CRC16_MODBUS_INCLUDED -#include - #include "platform.h" -#include "private/crc16_poly_0x8005.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_modbus 16 bit CRC MODBUS calculation +//\defgroup crc16_modbus 16 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc16_poly_0x8005<0xFFFFU, 0x0000U, true> crc16_modbus; -} +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_modbus_t = etl::crc_type; +#else + template + class crc16_modbus_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_modbus_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_modbus_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_modbus_t<256U> crc16_modbus_t256; + typedef etl::crc16_modbus_t<16U> crc16_modbus_t16; + typedef etl::crc16_modbus_t<4U> crc16_modbus_t4; + typedef crc16_modbus_t256 crc16_modbus; +} #endif diff --git a/include/etl/crc16_usb.h b/include/etl/crc16_usb.h index 0538eb58..2a2528f6 100644 --- a/include/etl/crc16_usb.h +++ b/include/etl/crc16_usb.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2018 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -31,21 +31,48 @@ SOFTWARE. #ifndef ETL_CRC16_USB_INCLUDED #define ETL_CRC16_USB_INCLUDED -#include - #include "platform.h" -#include "private/crc16_poly_0x8005.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_modbus 16 bit CRC USB calculation +///\defgroup crc16_usb 16 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc16_poly_0x8005<0xFFFFU, 0xFFFFU, true> crc16_usb; -} +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_usb_t = etl::crc_type; +#else + template + class crc16_usb_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_usb_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_usb_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_usb_t<256U> crc16_usb_t256; + typedef etl::crc16_usb_t<16U> crc16_usb_t16; + typedef etl::crc16_usb_t<4U> crc16_usb_t4; + typedef crc16_usb_t256 crc16_usb; +} #endif diff --git a/include/etl/crc16_x25.h b/include/etl/crc16_x25.h index e2ec150b..829daa7f 100644 --- a/include/etl/crc16_x25.h +++ b/include/etl/crc16_x25.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2019 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC16_X25_INCLUDED #include "platform.h" -#include "private/crc16_poly_0x1021_.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_aug_ccitt 16 bit CRC X25 calculation +///\defgroup crc16_x25 16 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc16_poly_0x1021<0xFFFFU, 0xFFFFU, true> crc16_x25; -} +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_x25_t = etl::crc_type; +#else + template + class crc16_x25_t : public etl::private_crc::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_x25_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_x25_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_x25_t<256U> crc16_x25_t256; + typedef etl::crc16_x25_t<16U> crc16_x25_t16; + typedef etl::crc16_x25_t<4U> crc16_x25_t4; + typedef crc16_x25_t256 crc16_x25; +} #endif diff --git a/include/etl/crc16_xmodem.h b/include/etl/crc16_xmodem.h index 3c0f6ec4..153ea8bd 100644 --- a/include/etl/crc16_xmodem.h +++ b/include/etl/crc16_xmodem.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2019 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC16_XMODEM_INCLUDED #include "platform.h" -#include "private/crc16_poly_0x1021_.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_xmodem 16 bit CRC XMODEM calculation +///\defgroup crc16_xmodem 16 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc16_poly_0x1021<0x0000U, 0x0000U, false> crc16_xmodem; -} +#if ETL_CPP11_SUPPORTED + template + using crc16_xmodem_t = etl::crc_type; +#else + template + class crc16_xmodem_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_xmodem_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_xmodem_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_xmodem_t<256U> crc16_xmodem_t256; + typedef etl::crc16_xmodem_t<16U> crc16_xmodem_t16; + typedef etl::crc16_xmodem_t<4U> crc16_xmodem_t4; + typedef crc16_xmodem_t256 crc16_xmodem; +} #endif diff --git a/include/etl/crc32.h b/include/etl/crc32.h index 463f3e38..69d78003 100644 --- a/include/etl/crc32.h +++ b/include/etl/crc32.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2014 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC32_INCLUDED #include "platform.h" -#include "private/crc32_poly_0x04c11db7.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif +#include "private/crc_implementation.h" ///\defgroup crc32 32 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc32_poly_0x04c11db7<0xFFFFFFFFU, 0xFFFFFFFFU, true> crc32; -} +#if ETL_CPP11_SUPPORTED + template + using crc32_t = etl::crc_type; +#else + template + class crc32_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc32_t<256U> crc32_t256; + typedef etl::crc32_t<16U> crc32_t16; + typedef etl::crc32_t<4U> crc32_t4; + typedef crc32_t256 crc32; +} #endif diff --git a/include/etl/crc32_bzip2.h b/include/etl/crc32_bzip2.h index 488b297e..2b8a0808 100644 --- a/include/etl/crc32_bzip2.h +++ b/include/etl/crc32_bzip2.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2019 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC32_BZIP2_INCLUDED #include "platform.h" -#include "private/crc32_poly_0x04c11db7.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc32 BZIP2 32 bit CRC calculation +///\defgroup crc32_bzip2 32 bit CRC BZIP2 calculation ///\ingroup crc namespace etl { - typedef crc32_poly_0x04c11db7<0xFFFFFFFFU, 0xFFFFFFFFU, false> crc32_bzip2; -} +#if ETL_CPP11_SUPPORTED + template + using crc32_bzip2_t = etl::crc_type; +#else + template + class crc32_bzip2_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_bzip2_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_bzip2_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc32_bzip2_t<256U> crc32_bzip2_t256; + typedef etl::crc32_bzip2_t<16U> crc32_bzip2_t16; + typedef etl::crc32_bzip2_t<4U> crc32_bzip2_t4; + typedef crc32_bzip2_t256 crc32_bzip2; +} #endif diff --git a/include/etl/crc32_c.h b/include/etl/crc32_c.h index fb012be6..44b23144 100644 --- a/include/etl/crc32_c.h +++ b/include/etl/crc32_c.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2018 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC32_C_INCLUDED #include "platform.h" -#include "private/crc32_poly_0x1edc6f41.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc32_c 32 bit CRC-C calculation (Castagnoli) +///\defgroup crc32_c 32 bit CRC_C calculation ///\ingroup crc namespace etl { - typedef crc32_poly_0x1edc6f41<0xFFFFFFFFU, 0xFFFFFFFFU, true> crc32_c; -} +#if ETL_CPP11_SUPPORTED + template + using crc32_c_t = etl::crc_type; +#else + template + class crc32_c_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_c_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_c_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc32_c_t<256U> crc32_c_t256; + typedef etl::crc32_c_t<16U> crc32_c_t16; + typedef etl::crc32_c_t<4U> crc32_c_t4; + typedef crc32_c_t256 crc32_c; +} #endif diff --git a/include/etl/crc32_mpeg2.h b/include/etl/crc32_mpeg2.h index d085c212..42c15482 100644 --- a/include/etl/crc32_mpeg2.h +++ b/include/etl/crc32_mpeg2.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2019 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC32_MPEG2_INCLUDED #include "platform.h" -#include "private/crc32_poly_0x04c11db7.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc32 MPEG2 32 bit CRC calculation +///\defgroup crc32_mpeg2 32 bit CRC MPEG2 calculation ///\ingroup crc namespace etl { - typedef crc32_poly_0x04c11db7<0xFFFFFFFFU, 0x00000000U, false> crc32_mpeg2; -} +#if ETL_CPP11_SUPPORTED + template + using crc32_mpeg2_t = etl::crc_type; +#else + template + class crc32_mpeg2_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_mpeg2_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_mpeg2_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc32_mpeg2_t<256U> crc32_mpeg2_t256; + typedef etl::crc32_mpeg2_t<16U> crc32_mpeg2_t16; + typedef etl::crc32_mpeg2_t<4U> crc32_mpeg2_t4; + typedef crc32_mpeg2_t256 crc32_mpeg2; +} #endif diff --git a/include/etl/crc32_posix.h b/include/etl/crc32_posix.h index 1219248a..6f9a2e1c 100644 --- a/include/etl/crc32_posix.h +++ b/include/etl/crc32_posix.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2019 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC32_POSIX_INCLUDED #include "platform.h" -#include "private/crc32_poly_0x04c11db7.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc32 POSIX 32 bit CRC calculation +///\defgroup crc32_posix 32 bit CRC POSIX calculation ///\ingroup crc namespace etl { - typedef crc32_poly_0x04c11db7<0x00000000U, 0xFFFFFFFFU, false> crc32_posix; -} +#if ETL_CPP11_SUPPORTED + template + using crc32_posix_t = etl::crc_type; +#else + template + class crc32_posix_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_posix_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_posix_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc32_posix_t<256U> crc32_posix_t256; + typedef etl::crc32_posix_t<16U> crc32_posix_t16; + typedef etl::crc32_posix_t<4U> crc32_posix_t4; + typedef crc32_posix_t256 crc32_posix; +} #endif diff --git a/include/etl/crc64_ecma.h b/include/etl/crc64_ecma.h index a7d263a3..c15dc654 100644 --- a/include/etl/crc64_ecma.h +++ b/include/etl/crc64_ecma.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2014 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -32,18 +32,47 @@ SOFTWARE. #define ETL_CRC64_ECMA_INCLUDED #include "platform.h" -#include "private/crc64_poly_0x42f0e1eba9ea3693.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc64_ecma 64 bit CRC ECMA calculation +///\defgroup crc64_ecma 64 bit ECMA CRC calculation ///\ingroup crc namespace etl { - typedef crc64_poly_0x42f0e1eba9ea3693<0x0000000000000000U, 0x0000000000000000U, false> crc64_ecma; -} +#if ETL_CPP11_SUPPORTED + template + using crc64_ecma_t = etl::crc_type; +#else + template + class crc64_ecma_t : public etl::crc_type + { + public: + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc64_ecma_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc64_ecma_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc64_ecma_t<256U> crc64_ecma_t256; + typedef etl::crc64_ecma_t<16U> crc64_ecma_t16; + typedef etl::crc64_ecma_t<4U> crc64_ecma_t4; + typedef crc64_ecma_t256 crc64_ecma; +} #endif diff --git a/include/etl/crc8_ccitt.h b/include/etl/crc8_ccitt.h index 3c807f99..4ebe9277 100644 --- a/include/etl/crc8_ccitt.h +++ b/include/etl/crc8_ccitt.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2014 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -28,22 +28,49 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_CRC8_CCITT_INCLUDED -#define ETL_CRC8_CCITT_INCLUDED +#ifndef ETL_CRC8_CCITT_EXP_INCLUDED +#define ETL_CRC8_CCITT_EXP_INCLUDED #include "platform.h" -#include "private/crc8_poly_0x07.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc8_ccitt 8 bit CRC calculation -///\ingroup crc +#include "private/crc_implementation.h" namespace etl { - typedef crc8_poly_0x07<0x00U, 0x00U, false> crc8_ccitt; +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_ccitt_t = etl::crc_type; +#else + template + class crc8_ccitt_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_ccitt_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_ccitt_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef crc8_ccitt_t<256U> crc8_ccitt_t256; + typedef crc8_ccitt_t<16U> crc8_ccitt_t16; + typedef crc8_ccitt_t<4U> crc8_ccitt_t4; + typedef crc8_ccitt_t256 crc8_ccitt; } #endif diff --git a/include/etl/crc8_rohc.h b/include/etl/crc8_rohc.h index 85217da8..de15247c 100644 --- a/include/etl/crc8_rohc.h +++ b/include/etl/crc8_rohc.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2019 jwellbelove +Copyright(c) 2021 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -28,22 +28,52 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_CRC8_ROHC_INCLUDED -#define ETL_CRC8_ROHC_INCLUDED +#ifndef ETL_CRC8_ROHC_EXP_INCLUDED +#define ETL_CRC8_ROHC_EXP_INCLUDED #include "platform.h" -#include "private/crc8_poly_0x07.h" +#include "private/crc_implementation.h" -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc8_ccitt 8 bit CRC calculation +///\defgroup rohc 8 bit CRC calculation ///\ingroup crc namespace etl { - typedef crc8_poly_0x07<0xFF, 0x00, true> crc8_rohc; +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_rohc_t = etl::crc_type; +#else + template + class crc8_rohc_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_rohc_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_rohc_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_rohc_t<256U> crc8_rohc_t256; + typedef etl::crc8_rohc_t<16U> crc8_rohc_t16; + typedef etl::crc8_rohc_t<4U> crc8_rohc_t4; + typedef crc8_rohc_t256 crc8_rohc; } #endif diff --git a/include/etl/experimental/crc.h b/include/etl/experimental/crc.h deleted file mode 100644 index 4948719d..00000000 --- a/include/etl/experimental/crc.h +++ /dev/null @@ -1,82 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2021 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef ETL_CRC8_CCITT_EXP_INCLUDED -#define ETL_CRC8_CCITT_EXP_INCLUDED - -#include "../platform.h" -#include "crc_implementation.h" -#include "crc_parameters.h" - -namespace etl -{ - namespace crc - { -#if ETL_CPP11_SUPPORTED - template - using crc8_ccitt_t = etl::private_crc::crc_type; -#else - template - class crc8_ccitt_t : public etl::private_crc::crc_type - { - public: - - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc8_ccitt_t() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc8_ccitt_t(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; -#endif - - typedef crc8_ccitt_t<256U> crc8_ccitt_t256; - typedef crc8_ccitt_t<16U> crc8_ccitt_t16; - typedef crc8_ccitt_t<4U> crc8_ccitt_t4; - typedef crc8_ccitt_t256 crc8_ccitt; - } -} - -#endif diff --git a/include/etl/experimental/crc16.h b/include/etl/experimental/crc16.h index 68d921b4..07b0c39d 100644 --- a/include/etl/experimental/crc16.h +++ b/include/etl/experimental/crc16.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC16_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc16 16 bit CRC calculation diff --git a/include/etl/experimental/crc16_aug_ccitt.h b/include/etl/experimental/crc16_aug_ccitt.h deleted file mode 100644 index 8496ad70..00000000 --- a/include/etl/experimental/crc16_aug_ccitt.h +++ /dev/null @@ -1,88 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2021 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef ETL_CRC16_AUG_CCITT_EX_INCLUDED -#define ETL_CRC16_AUG_CCITT_EX_INCLUDED - -#include "../platform.h" -#include "crc_implementation_2.h" -#include "crc_parameters.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_aug_ccitt 16 bit CRC calculation -///\ingroup crc - -namespace etl -{ - namespace crc - { -#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 - template - using crc16_aug_ccitt_t = etl::crc_type; -#else - template - class crc16_aug_ccitt_t : public etl::crc_type - { - public: - - - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc16_aug_ccitt_t() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc16_aug_ccitt_t(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; -#endif - - typedef etl::crc::crc16_aug_ccitt_t<256U> crc16_aug_ccitt_t256; - typedef etl::crc::crc16_aug_ccitt_t<16U> crc16_aug_ccitt_t16; - typedef etl::crc::crc16_aug_ccitt_t<4U> crc16_aug_ccitt_t4; - typedef crc16_aug_ccitt_t256 crc16_aug_ccitt; - } -} -#endif diff --git a/include/etl/experimental/crc16_ccitt.h b/include/etl/experimental/crc16_ccitt.h index 0039f602..be148a56 100644 --- a/include/etl/experimental/crc16_ccitt.h +++ b/include/etl/experimental/crc16_ccitt.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC16_CCITT_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc16_ccitt 16 bit CRC calculation diff --git a/include/etl/experimental/crc16_genibus.h b/include/etl/experimental/crc16_genibus.h index d2707c55..f901ab8f 100644 --- a/include/etl/experimental/crc16_genibus.h +++ b/include/etl/experimental/crc16_genibus.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC16_GENIBUS_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc16_genibus 16 bit CRC calculation diff --git a/include/etl/experimental/crc16_kermit.h b/include/etl/experimental/crc16_kermit.h index bcbbd85d..eb9cc987 100644 --- a/include/etl/experimental/crc16_kermit.h +++ b/include/etl/experimental/crc16_kermit.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC16_KERMIT_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc16_kermit 16 bit CRC calculation diff --git a/include/etl/experimental/crc16_modbus.h b/include/etl/experimental/crc16_modbus.h index 94bdf574..aca95d3b 100644 --- a/include/etl/experimental/crc16_modbus.h +++ b/include/etl/experimental/crc16_modbus.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC16_MODBUS_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" //\defgroup crc16_modbus 16 bit CRC calculation diff --git a/include/etl/experimental/crc16_usb.h b/include/etl/experimental/crc16_usb.h index 914a1a49..2510d78b 100644 --- a/include/etl/experimental/crc16_usb.h +++ b/include/etl/experimental/crc16_usb.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC16_USB_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc16_usb 16 bit CRC calculation diff --git a/include/etl/experimental/crc16_x25.h b/include/etl/experimental/crc16_x25.h index 33e34866..916c15a7 100644 --- a/include/etl/experimental/crc16_x25.h +++ b/include/etl/experimental/crc16_x25.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC16_X25_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc16_x25 16 bit CRC calculation diff --git a/include/etl/experimental/crc16_xmodem.h b/include/etl/experimental/crc16_xmodem.h index 24ef637f..19c520af 100644 --- a/include/etl/experimental/crc16_xmodem.h +++ b/include/etl/experimental/crc16_xmodem.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC16_XMODEM_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc16_xmodem 16 bit CRC calculation diff --git a/include/etl/experimental/crc32.h b/include/etl/experimental/crc32.h index c3bbf70a..37767d2f 100644 --- a/include/etl/experimental/crc32.h +++ b/include/etl/experimental/crc32.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC32_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc32 32 bit CRC calculation diff --git a/include/etl/experimental/crc32_bzip2.h b/include/etl/experimental/crc32_bzip2.h index 5b04a078..5d632d76 100644 --- a/include/etl/experimental/crc32_bzip2.h +++ b/include/etl/experimental/crc32_bzip2.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC32_BZIP2_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc32_bzip2 32 bit CRC BZIP2 calculation diff --git a/include/etl/experimental/crc32_c.h b/include/etl/experimental/crc32_c.h index f9df5c2a..84d84167 100644 --- a/include/etl/experimental/crc32_c.h +++ b/include/etl/experimental/crc32_c.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC32_C_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc32_c 32 bit CRC_C calculation diff --git a/include/etl/experimental/crc32_mpeg2.h b/include/etl/experimental/crc32_mpeg2.h index 5b04a078..e23657a4 100644 --- a/include/etl/experimental/crc32_mpeg2.h +++ b/include/etl/experimental/crc32_mpeg2.h @@ -28,14 +28,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_CRC32_BZIP2_EX_INCLUDED -#define ETL_CRC32_BZIP2_EX_INCLUDED +#ifndef ETL_CRC32_MPEG2_EX_INCLUDED +#define ETL_CRC32_MPEG2_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" -///\defgroup crc32_bzip2 32 bit CRC BZIP2 calculation +///\defgroup crc32_mpeg2 32 bit CRC MPEG2 calculation ///\ingroup crc namespace etl @@ -44,17 +44,17 @@ namespace etl { #if ETL_CPP11_SUPPORTED template - using crc32_bzip2_t = etl::crc_type; + using crc32_mpeg2_t = etl::crc_type; #else template - class crc32_bzip2_t : public etl::crc_type + class crc32_mpeg2_t : public etl::crc_type { public: //************************************************************************* /// Default constructor. //************************************************************************* - crc32_bzip2_t() + crc32_mpeg2_t() { this->reset(); } @@ -65,7 +65,7 @@ namespace etl /// \param end End of the range. //************************************************************************* template - crc32_bzip2_t(TIterator begin, const TIterator end) + crc32_mpeg2_t(TIterator begin, const TIterator end) { this->reset(); this->add(begin, end); @@ -73,10 +73,10 @@ namespace etl }; #endif - typedef etl::crc::crc32_bzip2_t<256U> crc32_bzip2_t256; - typedef etl::crc::crc32_bzip2_t<16U> crc32_bzip2_t16; - typedef etl::crc::crc32_bzip2_t<4U> crc32_bzip2_t4; - typedef crc32_bzip2_t256 crc32_bzip2; + typedef etl::crc::crc32_mpeg2_t<256U> crc32_mpeg2_t256; + typedef etl::crc::crc32_mpeg2_t<16U> crc32_mpeg2_t16; + typedef etl::crc::crc32_mpeg2_t<4U> crc32_mpeg2_t4; + typedef crc32_mpeg2_t256 crc32_mpeg2; } } #endif diff --git a/include/etl/experimental/crc32_posix.h b/include/etl/experimental/crc32_posix.h index bce4492e..5f3cb701 100644 --- a/include/etl/experimental/crc32_posix.h +++ b/include/etl/experimental/crc32_posix.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC32_POSIX_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc32_posix 32 bit CRC POSIX calculation diff --git a/include/etl/experimental/crc64_ecma.h b/include/etl/experimental/crc64_ecma.h index 3a7aebe3..407c0f4a 100644 --- a/include/etl/experimental/crc64_ecma.h +++ b/include/etl/experimental/crc64_ecma.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC64_ECMA_EX_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup crc64_ecma 64 bit ECMA CRC calculation diff --git a/include/etl/experimental/crc8_ccitt.h b/include/etl/experimental/crc8_ccitt.h index 4f6d8d2d..66683b68 100644 --- a/include/etl/experimental/crc8_ccitt.h +++ b/include/etl/experimental/crc8_ccitt.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC8_CCITT_EXP_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" namespace etl diff --git a/include/etl/experimental/crc8_rohc.h b/include/etl/experimental/crc8_rohc.h index d01d7e91..60ab5b23 100644 --- a/include/etl/experimental/crc8_rohc.h +++ b/include/etl/experimental/crc8_rohc.h @@ -32,7 +32,7 @@ SOFTWARE. #define ETL_CRC8_ROHC_EXP_INCLUDED #include "../platform.h" -#include "crc_implementation_2.h" +#include "crc_implementation.h" #include "crc_parameters.h" ///\defgroup rohc 8 bit CRC calculation diff --git a/include/etl/experimental/crc8_table16.h b/include/etl/experimental/crc8_table16.h deleted file mode 100644 index e7ad5988..00000000 --- a/include/etl/experimental/crc8_table16.h +++ /dev/null @@ -1,234 +0,0 @@ - -#pragma once - -#include "../platform.h" -#include "../frame_check_sequence.h" - -#include "../binary.h" - -#include "stdint.h" - -namespace etl -{ - namespace crc - { - //***************************************************************************** - // - //***************************************************************************** - template - struct crc8_policy_table16; - - //***************************************************************************** - // Specialisation for Reflect = false - //***************************************************************************** - template - struct crc8_policy_table16 - { - static ETL_CONSTANT uint8_t Mask = 0x0FU; - static ETL_CONSTANT uint8_t Chunk_Size = 4U; - - typedef uint8_t value_type; - - //***************************************************************************** - template - class entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT bool Do_Poly = (Entry & (uint8_t(1U) << (Accumulator_Bits - 1U))) != 0U; - static ETL_CONSTANT uint8_t value = uint8_t(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); - }; - - //************************************************************************* - template - class table_entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = entry::Accumulator_Bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_Size); - static ETL_CONSTANT uint8_t Entry = uint8_t(Index << Shift_Bits); - - static ETL_CONSTANT uint8_t value = entry::value>::value>::value>::value; - }; - - //************************************************************************* - ETL_CONSTEXPR uint8_t initial() const - { - return Initial; - } - - //************************************************************************* - uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* table) const - { - // Extract the most significant nibble of the crc and xor with the value nibble. - uint8_t index = (crc >> (etl::integral_limits::bits - Chunk_Size)) ^ value; - - crc <<= Chunk_Size; - crc ^= table[index]; - - return crc; - } - - //************************************************************************* - uint8_t add(uint8_t crc, uint8_t value) const - { - static ETL_CONSTANT uint8_t table[16] = - { - table_entry<0U, Polynomial>::value, - table_entry<1U, Polynomial>::value, - table_entry<2U, Polynomial>::value, - table_entry<3U, Polynomial>::value, - table_entry<4U, Polynomial>::value, - table_entry<5U, Polynomial>::value, - table_entry<6U, Polynomial>::value, - table_entry<7U, Polynomial>::value, - table_entry<8U, Polynomial>::value, - table_entry<9U, Polynomial>::value, - table_entry<10U, Polynomial>::value, - table_entry<11U, Polynomial>::value, - table_entry<12U, Polynomial>::value, - table_entry<13U, Polynomial>::value, - table_entry<14U, Polynomial>::value, - table_entry<15U, Polynomial>::value - }; - - crc = update_chunk(crc, (value >> Chunk_Size) & Mask, table); - crc = update_chunk(crc, value & Mask, table); - - return crc; - } - - //************************************************************************* - uint8_t final(uint8_t crc) const - { - return crc ^ Xor_Out; - } - }; - - //***************************************************************************** - // Specialisation for Reflect = true - //***************************************************************************** - template - struct crc8_policy_table16 - { - static ETL_CONSTANT uint8_t Mask = 0x0FU; - static ETL_CONSTANT uint8_t Chunk_Size = 4U; - - typedef uint8_t value_type; - - //***************************************************************************** - template - class entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT bool Do_Poly = (Entry & uint8_t(1U)) != 0U; - static ETL_CONSTANT uint8_t value = uint8_t(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const::value : (Entry >> 1U)); - }; - - //************************************************************************* - template - class table_entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = entry::Accumulator_Bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_Size); - static ETL_CONSTANT uint8_t Entry = uint8_t(Index << Shift_Bits); - - static ETL_CONSTANT uint8_t value = entry::value>::value>::value>::value; - }; - - //************************************************************************* - ETL_CONSTEXPR uint8_t initial() const - { - return Initial; - } - - //************************************************************************* - uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* const table) const - { - // Extract the most significant nibble of the crc and xor with the value nibble. - uint8_t index = (crc >> (Accumulator_Bits - 4U)) ^ value; - - crc <<= Chunk_Size; - crc ^= table[index]; - - return crc; - } - - //************************************************************************* - uint8_t add(uint8_t crc, uint8_t value) const - { - static ETL_CONSTANT uint8_t table[16] = - { - table_entry<0U, Polynomial>::value, - table_entry<1U, Polynomial>::value, - table_entry<2U, Polynomial>::value, - table_entry<3U, Polynomial>::value, - table_entry<4U, Polynomial>::value, - table_entry<5U, Polynomial>::value, - table_entry<6U, Polynomial>::value, - table_entry<7U, Polynomial>::value, - table_entry<8U, Polynomial>::value, - table_entry<9U, Polynomial>::value, - table_entry<10U, Polynomial>::value, - table_entry<11U, Polynomial>::value, - table_entry<12U, Polynomial>::value, - table_entry<13U, Polynomial>::value, - table_entry<14U, Polynomial>::value, - table_entry<15U, Polynomial>::value - }; - - crc = update_chunk(crc, (value >> Chunk_Size) & Mask, table); // high nibble - crc = update_chunk(crc, value & Mask, table); // low nibble - - return crc; - } - - //************************************************************************* - uint8_t final(uint8_t crc) const - { - return crc ^ Xor_Out; - } - }; - - //***************************************************************************** - // - //***************************************************************************** - template - class crc8_table16 : public etl::frame_check_sequence > - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc8_table16() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc8_table16(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; - } -} diff --git a/include/etl/experimental/crc8_table256.h b/include/etl/experimental/crc8_table256.h deleted file mode 100644 index bd9c187c..00000000 --- a/include/etl/experimental/crc8_table256.h +++ /dev/null @@ -1,347 +0,0 @@ - -#pragma once - -#include "../platform.h" -#include "../frame_check_sequence.h" -#include "../binary.h" - -#include "crc_common.h" - -#include "stdint.h" - -namespace etl -{ - namespace crc - { - //***************************************************************************** - // - //***************************************************************************** - template - struct crc8_policy_table256 - { - static ETL_CONSTANT uint8_t Chunk_Mask = etl::private_crc::crc_traits<256U>::Chunk_Mask; - static ETL_CONSTANT uint8_t Chunk_Bits = etl::private_crc::crc_traits<256U>::Chunk_Bits; - - typedef uint8_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint8_t initial() const - { - return Initial; - } - - //************************************************************************* - static uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* const table) - { - uint8_t t = crc ^ value; - - crc = table[t]; - - return crc; - } - - //************************************************************************* - uint8_t add(uint8_t crc, uint8_t value) const - { - static ETL_CONSTANT uint8_t table[256] = - { - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value, - etl::private_crc::table_entry::value - }; - - crc = update_chunk(crc, value, table); - - return crc; - } - - //************************************************************************* - uint8_t final(uint8_t crc) const - { - return crc ^ Xor_Out; - } - }; - - //***************************************************************************** - // - //***************************************************************************** - template - class crc8_table256 : public etl::frame_check_sequence > - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc8_table256() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc8_table256(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; - } -} diff --git a/include/etl/experimental/crc8_table4.h b/include/etl/experimental/crc8_table4.h deleted file mode 100644 index e69e815e..00000000 --- a/include/etl/experimental/crc8_table4.h +++ /dev/null @@ -1,212 +0,0 @@ - -#pragma once - -#include "../platform.h" -#include "../frame_check_sequence.h" - -#include "../binary.h" - -#include "stdint.h" - -namespace etl -{ - namespace crc - { - //***************************************************************************** - // - //***************************************************************************** - template - struct crc8_policy_table4; - - //***************************************************************************** - // Specialisation for Reflect = false - //***************************************************************************** - template - struct crc8_policy_table4 - { - static ETL_CONSTANT uint8_t Mask = 0x03U; - static ETL_CONSTANT uint8_t Chunk_Size = 2U; - - typedef uint8_t value_type; - - //***************************************************************************** - template - class entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT bool Do_Poly = (Entry & (uint8_t(1U) << (Accumulator_Bits - 1U))) != 0U; - static ETL_CONSTANT uint8_t value = uint8_t(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); - }; - - //************************************************************************* - template - class table_entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = entry::Accumulator_Bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_Size); - static ETL_CONSTANT uint8_t Entry = uint8_t(Index << Shift_Bits); - - static ETL_CONSTANT uint8_t value = entry::value>::value; - }; - - //************************************************************************* - ETL_CONSTEXPR uint8_t initial() const - { - return Initial; - } - - //************************************************************************* - uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* table) const - { - // Extract the most significant nibble of the crc and xor with the value nibble. - uint8_t index = (crc >> (etl::integral_limits::bits - Chunk_Size)) ^ value; - - crc <<= Chunk_Size; - crc ^= table[index]; - - return crc; - } - - //************************************************************************* - uint8_t add(uint8_t crc, uint8_t value) const - { - static ETL_CONSTANT uint8_t table[4] = - { - table_entry<0U, Polynomial>::value, - table_entry<1U, Polynomial>::value, - table_entry<2U, Polynomial>::value, - table_entry<3U, Polynomial>::value - }; - - crc = update_chunk(crc, (value >> (Chunk_Size * 3U)) & Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Size * 2U)) & Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Size * 1U)) & Mask, table); - crc = update_chunk(crc, value & Mask, table); - - return crc; - } - - //************************************************************************* - uint8_t final(uint8_t crc) const - { - return crc ^ Xor_Out; - } - }; - - //***************************************************************************** - // Specialisation for Reflect = true - //***************************************************************************** - template - struct crc8_policy_table4 - { - static ETL_CONSTANT uint8_t Mask = 0x03; - static ETL_CONSTANT uint8_t Chunk_Size = 2U; - - typedef uint8_t value_type; - - //***************************************************************************** - template - class entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT bool Do_Poly = (Entry & uint8_t(1U)) != 0U; - static ETL_CONSTANT uint8_t value = uint8_t(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const::value : (Entry >> 1U)); - }; - - //************************************************************************* - template - class table_entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = entry::Accumulator_Bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_Size); - static ETL_CONSTANT uint8_t Entry = uint8_t(Index << Shift_Bits); - - static ETL_CONSTANT uint8_t value = entry::value>::value>::value>::value; - }; - - //************************************************************************* - ETL_CONSTEXPR uint8_t initial() const - { - return Initial; - } - - //************************************************************************* - uint8_t update_chunk(uint8_t crc, uint8_t value, const uint8_t* const table) const - { - // Extract the most significant nibble of the crc and xor with the value nibble. - uint8_t index = (crc >> (Accumulator_Bits - Chunk_Size)) ^ value; - - crc <<= Chunk_Size; - crc ^= table[index]; - - return crc; - } - - //************************************************************************* - uint8_t add(uint8_t crc, uint8_t value) const - { - static ETL_CONSTANT uint8_t table[4] = - { - table_entry<0U, Polynomial>::value, - table_entry<1U, Polynomial>::value, - table_entry<2U, Polynomial>::value, - table_entry<3U, Polynomial>::value - }; - - crc = update_chunk(crc, (value >> (Chunk_Size * 3U)) & Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Size * 2U)) & Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Size * 1U)) & Mask, table); - crc = update_chunk(crc, value & Mask, table); - - return crc; - } - - //************************************************************************* - uint8_t final(uint8_t crc) const - { - return crc ^ Xor_Out; - } - }; - - //***************************************************************************** - // - //***************************************************************************** - template - class crc8_table4 : public etl::frame_check_sequence > - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc8_table4() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc8_table4(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; - } -} diff --git a/include/etl/experimental/crc_implementation.h b/include/etl/experimental/crc_implementation.h deleted file mode 100644 index 2935cda6..00000000 --- a/include/etl/experimental/crc_implementation.h +++ /dev/null @@ -1,656 +0,0 @@ - -#pragma once - -#include "../platform.h" -#include "../frame_check_sequence.h" -#include "../static_assert.h" -#include "../binary.h" - -#include "stdint.h" - -namespace etl -{ - namespace private_crc - { - //***************************************************************************** - /// CRC Traits - //***************************************************************************** - template - struct crc_traits - { - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - }; - - //********************************* - // Traits for table size of 4. - template <> - struct crc_traits<4U> - { - static ETL_CONSTANT uint8_t Chunk_Mask = 0x03U; - static ETL_CONSTANT size_t Chunk_Bits = 2U; - }; - - //********************************* - // Traits for table size of 16. - template <> - struct crc_traits<16U> - { - static ETL_CONSTANT uint8_t Chunk_Mask = 0x0FU; - static ETL_CONSTANT size_t Chunk_Bits = 4U; - }; - - //********************************* - // Traits for table size of 256. - template <> - struct crc_traits<256U> - { - static ETL_CONSTANT uint8_t Chunk_Mask = 0xFFU; - static ETL_CONSTANT size_t Chunk_Bits = 8U; - }; - - //***************************************************************************** - /// CRC Entry - //***************************************************************************** - template - class crc_entry; - - //********************************* - // Not reflected - template - class crc_entry - { - private: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1U))) != 0U; - - public: - - static ETL_CONSTANT TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); - }; - - //********************************* - // Reflected - template - class crc_entry - { - private: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT bool Do_Poly = (Entry & TAccumulator(1U)) != 0U; - - public: - - static ETL_CONSTANT TAccumulator value = TAccumulator(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const::value : (Entry >> 1U)); - }; - - //***************************************************************************** - /// CRC Table Entry - //***************************************************************************** - template - class crc_table_entry - { - ETL_STATIC_ASSERT((Chunk_Bits == 2U) || (Chunk_Bits == 4U) || (Chunk_Bits == 8U), "Chunk bits must be 2, 4 or 8"); - }; - - //********************************* - // Chunk bit size of 8. - template - class crc_table_entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 8U); - static ETL_CONSTANT TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); - - static ETL_CONSTANT TAccumulator value = crc_entry::value>::value>::value>::value>::value>::value>::value>::value; - }; - - //********************************* - // Chunk bit size of 4. - template - class crc_table_entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 4U); - static ETL_CONSTANT TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); - - static const TAccumulator value = crc_entry::value>::value>::value>::value; - }; - - //********************************* - // Chunk bit size of 2. - template - class crc_table_entry - { - public: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 2U); - static ETL_CONSTANT TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); - - static const TAccumulator value = crc_entry::value>::value; - }; - - //************************************************************************* - // Accumulator_Bits > Chunk_Bits and not reflected - template - typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && !Reflect, TAccumulator>::type - crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; - - crc <<= Chunk_Bits; - crc ^= table[index]; - - return crc; - } - - //************************************************************************* - // Accumulator_Bits > Chunk_Bits and reflected - template - typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && Reflect, TAccumulator>::type - crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - size_t index = (crc & Chunk_Mask) ^ value; - - crc >>= Chunk_Bits; - crc ^= table[index]; - - return crc; - } - - //************************************************************************* - // Accumulator_Bits == Chunk_Bits and not reflected - template - typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && !Reflect, TAccumulator>::type - crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; - - crc = table[index]; - - return crc; - } - - //************************************************************************* - // Accumulator_Bits == Chunk_Bits and reflected - template - typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && Reflect, TAccumulator>::type - crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - size_t index = (crc & Chunk_Mask) ^ value; - - crc = table[index]; - - return crc; - } - - //***************************************************************************** - // - //***************************************************************************** - template - struct crc_policy - { - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - }; - - //********************************* - template - struct crc_policy - { - static ETL_CONSTANT size_t Table_Size = 256U; - static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; - static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - - typedef TAccumulator value_type; - - //************************************************************************* - ETL_CONSTEXPR TAccumulator initial() const - { - return Initial; - } - - //************************************************************************* - TAccumulator add(TAccumulator crc, uint8_t value) const - { - static ETL_CONSTANT TAccumulator table[Table_Size] = - { - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value - }; - - crc = crc_update_chunk(crc, value, table); - - return crc; - } - - //************************************************************************* - TAccumulator final(TAccumulator crc) const - { - return crc ^ Xor_Out; - } - }; - - //********************************* - template - struct crc_policy - { - static ETL_CONSTANT size_t Table_Size = 16U; - static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; - static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - - typedef TAccumulator value_type; - - //************************************************************************* - ETL_CONSTEXPR TAccumulator initial() const - { - return Initial; - } - - //************************************************************************* - static TAccumulator update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - // Extract the most significant nibble of the crc and xor with the value nibble. - size_t index = (crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value; - - crc <<= Chunk_Bits; - crc ^= table[index]; - - return crc; - } - - //************************************************************************* - TAccumulator add(TAccumulator crc, uint8_t value) const - { - static ETL_CONSTANT TAccumulator table[Table_Size] = - { - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value - }; - - crc = update_chunk(crc, (value >> Chunk_Bits) & Chunk_Mask, table); - crc = update_chunk(crc, value & Chunk_Mask, table); - - return crc; - } - - //************************************************************************* - TAccumulator final(TAccumulator crc) const - { - return crc ^ Xor_Out; - } - }; - - - //********************************* - template - struct crc_policy - { - static ETL_CONSTANT size_t Table_Size = 4U; - static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; - static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - - typedef TAccumulator value_type; - - //************************************************************************* - ETL_CONSTEXPR TAccumulator initial() const - { - return Initial; - } - - //************************************************************************* - static TAccumulator update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - // Extract the most significant nibble of the crc and xor with the value nibble. - size_t index = (crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value; - - crc <<= Chunk_Bits; - crc ^= table[index]; - - return crc; - } - - //************************************************************************* - TAccumulator add(TAccumulator crc, uint8_t value) const - { - static ETL_CONSTANT TAccumulator table[Table_Size] = - { - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value - }; - - crc = update_chunk(crc, (value >> (Chunk_Bits * 3U)) & Chunk_Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Bits * 2U)) & Chunk_Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Bits * 1U)) & Chunk_Mask, table); - crc = update_chunk(crc, value & Chunk_Mask, table); - - return crc; - } - - //************************************************************************* - TAccumulator final(TAccumulator crc) const - { - return crc ^ Xor_Out; - } - }; - - //***************************************************************************** - /// - //***************************************************************************** - template - class crc_type : public etl::frame_check_sequence > - { - public: - - ETL_STATIC_ASSERT((Table_Size == 4U) || (Table_Size == 16U) || (Table_Size == 256U), "Table size must be 4, 16 or 256"); - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc_type() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc_type(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; - } -} diff --git a/include/etl/experimental/crc_table_16.h b/include/etl/experimental/crc_table_16.h deleted file mode 100644 index 05cb77f8..00000000 --- a/include/etl/experimental/crc_table_16.h +++ /dev/null @@ -1,701 +0,0 @@ - -#pragma once - -#include -#include - -//***************************************************************************** -template -class entry -{ -private: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1))) != 0U; - -public: - - static const TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); -}; - -//***************************************************************************** -/// 8 bit chunks -//***************************************************************************** -template -class table_entry_8 -{ -//private: -public: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const size_t Shift_Bits = size_t(Accumulator_Bits - 8U); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value>::value>::value>::value>::value>::value>::value; -}; - -//***************************************************************************** -/// 4 bit chunks -//***************************************************************************** -template -class table_entry_4 -{ -private: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_4_Bits); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value>::value>::value; -}; - -//***************************************************************************** -/// 2 bit chunks -//***************************************************************************** -template -class table_entry_2 -{ -private: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_2_Bits); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value; -}; - -//***************************************************************************** -template -struct crc_table; - -template -struct crc_table -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[256] = - { - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value - }; - - return table; - } -}; - -template -struct crc_table -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[16] = - { - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value - }; - - return table; - } -}; - -template -struct crc_table -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[4] = - { - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value - }; - - return table; - } -}; - - -// -// Define the CRC algorithm parameters -// -template -struct crc_algorithm -{ - using accumulator_type = TAccumulator; - static constexpr TAccumulator polynomial = Polynomial; - static constexpr TAccumulator initial_value = Initial; - static constexpr TAccumulator xor_out_value = Xor_Out; - static constexpr bool reverse = Reverse; -}; - -// -// Define the basic traits we use in our CRC accumulators and Table Lookup -// -template -struct crc_traits {}; - -template -struct crc_traits -{ - static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; - static constexpr std::size_t CHUNK_BITS = 2; - static constexpr uint8_t CHUNK_MASK = 0x03u; - static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; - - using table_type = std::array; -}; - -template -struct crc_traits -{ - static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; - static constexpr std::size_t CHUNK_BITS = 4; - static constexpr uint8_t CHUNK_MASK = 0x0Fu; - static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; - - using table_type = std::array; -}; - -template -struct crc_traits -{ - static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; - static constexpr std::size_t CHUNK_BITS = 8; - static constexpr uint8_t CHUNK_MASK = 0xFFu; - static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; - - using table_type = std::array; -}; - -// -// CRC rotation policies. -// -// Forward rotation means that we clock in data MSB->LSB and rotate the Accumulator register left -// Reverse rotation means that we clock in data LSB->MSB and rotate the Accumulator register right -// - -template -struct crc_forward_policy -{ - using traits = crc_traits; - - - [[nodiscard]] static constexpr TAccumulator update_impl_tiny( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_small( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_large( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value, table); // full byte - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_chunk( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - // ensure we have only 4 bits - value &= traits::CHUNK_MASK; - - // Extract the most significant nibble of the crc and xor with the value nibble - uint8_t t = (crc >> (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS)) ^ value; - - // special case for when chunk size is same as accumulator size. - if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { - // shit crc left the size of the nibble - crc <<= traits::CHUNK_BITS; - - // xor in the table data - crc ^= table[t]; - } - else { - crc = table[t]; - } - - return crc; - } - - [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) - { - // initialise with the register in the upper bits - TAccumulator entry = TAccumulator(index) << (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS); - - for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) - { - // We are processing MSBs / rotating left so we need to check the high bit - if (entry & (TAccumulator(1u) << (traits::ACCUMULATOR_BITS - 1))) { - entry = (entry << 1) ^ polynomial; - } - else { - entry = (entry << 1); - } - } - - return entry; - } - - [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) - { - return init; - } -}; - -template -struct crc_reverse_policy -{ - using traits = crc_traits; - - - [[nodiscard]] static constexpr TAccumulator update_impl_tiny( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_small( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble - crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_large( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value, table); // full byte - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_chunk( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - // ensure we have only 4 bits - value &= traits::CHUNK_MASK; - - // Extract the least significant nibble of the crc and xor with the value nibble - uint8_t t = (crc & traits::CHUNK_MASK) ^ value; - - // special case for when chunk size is same as accumulator size. - if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { - // shit crc right the size of a nibble - crc >>= traits::CHUNK_BITS; - - // xor in the table data - crc ^= table[t]; - } - else { - crc = table[t]; - } - - return crc; - } - - [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) - { - // initialise with the register in the lower bits - TAccumulator entry = TAccumulator(index); - - for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) - { - // we are processing LSBs/rotating right - if (entry & 0x1u) { - entry = (entry >> 1) ^ util::reverse_bits(polynomial); - } - else { - entry = (entry >> 1); - } - } - - return entry; - } - - [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) - { - return util::reverse_bits(init); - } -}; - - -// -// A generic CRC lookup table sized for computing a nibble (4 bits) at a time. -// -// This is can be a large reduction of table space storage for embedded devices. -// -template ::value>> -class crc_chunk_table -{ -public: - - using policy = typename std::conditional, crc_forward_policy>::type; - - using traits = typename policy::traits; - - - // update the given crc accumulator with the value - [[nodiscard]] static constexpr TAccumulator update(TAccumulator crc, uint8_t value) - { - if constexpr (Table_Size == size_t::tiny) { - return policy::update_impl_tiny(crc, value, m_Table); - } - else if constexpr (Table_Size == size_t::small) { - return policy::update_impl_small(crc, value, m_Table); - } - else if constexpr (Table_Size == size_t::large) { - return policy::update_impl_large(crc, value, m_Table); - } - else { - static_assert("Unknown size_t"); - } - } - - // the crc accumulator initial value may need to be modified by the policy - // to account for rotation direction - [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) - { - return policy::make_initial_value(init); - } - -private: - -}; - - -// -// The generic CRC accumulator that is table driven -// -template -class crc -{ -public: - using algorithm = TAlgorithm; - using accumulator_type = typename algorithm::accumulator_type; - - // - // Update the accumulator with a new byte - // - void update(uint8_t value) - { - m_crc = table_impl::update(m_crc, value); - } - - // - // Extract the final value of the accumulator. - // - [[nodiscard]] accumulator_type final() { return m_crc ^ algorithm::xor_out_value; } - - // - // Reset the state of the accumulator back to the INITIAL value. - // - void reset() { m_crc = table_impl::make_initial_value(algorithm::initial_value); } - - -private: - using table_impl = crc_chunk_table; - - accumulator_type m_crc = table_impl::make_initial_value(algorithm::initial_value); -}; \ No newline at end of file diff --git a/include/etl/experimental/crc_table_256.h b/include/etl/experimental/crc_table_256.h deleted file mode 100644 index bb6e45e8..00000000 --- a/include/etl/experimental/crc_table_256.h +++ /dev/null @@ -1,519 +0,0 @@ - -#pragma once - -#include -#include - -#include "../binary.h" -#include "../integral_limits.h" - -//***************************************************************************** -template -class entry -{ -private: - - static ETL_CONSTANT size_t Accumulator_Bits = etl::integral_limits::bits; - static ETL_CONSTANT bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1))) != 0U; - -public: - - static const TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); -}; - -//***************************************************************************** -/// 8 bit chunks -//***************************************************************************** -template -class table_entry_8 -{ -//private: -public: - - static const size_t Accumulator_Bits = entry::Accumulator_Bits; - static const size_t Shift_Bits = size_t(Accumulator_Bits - 8U); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value>::value>::value>::value>::value>::value>::value; -}; - -//***************************************************************************** -template -struct crc_table_256 -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[256] = - { - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value, - table_entry_8::value - }; - - return table; - } -}; -// -//// -//// Define the CRC algorithm parameters -//// -//template -//struct crc_algorithm -//{ -// using accumulator_type = TAccumulator; -// static constexpr TAccumulator polynomial = Polynomial; -// static constexpr TAccumulator initial_value = Initial; -// static constexpr TAccumulator xor_out_value = Xor_Out; -// static constexpr bool reverse = Reverse; -//}; -// -//// -//// Define the basic traits we use in our CRC accumulators and Table Lookup -//// -//template -//struct crc_traits {}; -// -//template -//struct crc_traits_256 -//{ -// static constexpr std::size_t ACCUMULATOR_BITS = etl::integral_limits::bits; -// static constexpr std::size_t CHUNK_BITS = 8; -// static constexpr uint8_t CHUNK_MASK = 0xFFu; -// static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; -// -// using table_type = std::array; -//}; -// -//// -//// CRC rotation policies. -//// -//// Forward rotation means that we clock in data MSB->LSB and rotate the Accumulator register left -//// Reverse rotation means that we clock in data LSB->MSB and rotate the Accumulator register right -//// -// -//template -//struct crc_forward_policy_256 -//{ -// typedef crc_traits_256 traits; -// -// ETL_NODISCARD static constexpr TAccumulator update_impl_256(TAccumulator crc, -// uint8_t value, -// typename traits::table_type const& table) -// { -// crc = update_chunk(crc, value, table); // full byte -// return crc; -// } -// -// ETL_NODISCARD static constexpr TAccumulator update_chunk(TAccumulator crc, -// uint8_t value, -// typename traits::table_type const& table) -// { -// value &= traits::CHUNK_MASK; -// -// // Extract the most significant nibble of the crc and xor with the value nibble -// uint8_t t = (crc >> (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS)) ^ value; -// -// // special case for when chunk size is same as accumulator size. -// if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { -// // shift crc left the size of the nibble -// crc <<= traits::CHUNK_BITS; -// -// // xor in the table data -// crc ^= table[t]; -// } -// else { -// crc = table[t]; -// } -// -// return crc; -// } -// -// ETL_NODISCARD static constexpr TAccumulator make_initial_value(TAccumulator init) -// { -// return init; -// } -//}; -// -//template -//struct crc_reverse_policy_256 -//{ -// typedef crc_traits_256 traits; -// -// ETL_NODISCARD static constexpr TAccumulator update_impl( -// TAccumulator crc, uint8_t value, typename traits::table_type const& table) -// { -// crc = update_chunk(crc, value, table); // full byte -// return crc; -// } -// -// ETL_NODISCARD static constexpr TAccumulator update_chunk( -// TAccumulator crc, uint8_t value, typename traits::table_type const& table) -// { -// // ensure we have only 4 bits -// value &= traits::CHUNK_MASK; -// -// // Extract the least significant nibble of the crc and xor with the value nibble -// uint8_t t = (crc & traits::CHUNK_MASK) ^ value; -// -// // special case for when chunk size is same as accumulator size. -// if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { -// // shit crc right the size of a nibble -// crc >>= traits::CHUNK_BITS; -// -// // xor in the table data -// crc ^= table[t]; -// } -// else { -// crc = table[t]; -// } -// -// return crc; -// } -// -// ETL_NODISCARD static constexpr TAccumulator make_initial_value(TAccumulator init) -// { -// return etl::reverse_bits(init); -// } -//}; -// -// -//// -//// A generic CRC lookup table sized for computing a nibble (4 bits) at a time. -//// -//// This is can be a large reduction of table space storage for embedded devices. -//// -//template ::value>> -//class crc_chunk_table -//{ -//public: -// -// using policy = typename std::conditional, crc_forward_policy>::type; -// -// using traits = typename policy::traits; -// -// -// // update the given crc accumulator with the value -// ETL_NODISCARD static constexpr TAccumulator update(TAccumulator crc, uint8_t value) -// { -// if constexpr (Table_Size == size_t::tiny) { -// return policy::update_impl_tiny(crc, value, m_Table); -// } -// else if constexpr (Table_Size == size_t::small) { -// return policy::update_impl_small(crc, value, m_Table); -// } -// else if constexpr (Table_Size == size_t::large) { -// return policy::update_impl_large(crc, value, m_Table); -// } -// else { -// static_assert("Unknown size_t"); -// } -// } -// -// // the crc accumulator initial value may need to be modified by the policy -// // to account for rotation direction -// ETL_NODISCARD static constexpr TAccumulator make_initial_value(TAccumulator init) -// { -// return policy::make_initial_value(init); -// } -// -//private: -// -//}; -// -// -//// -//// The generic CRC accumulator that is table driven -//// -//template -//class crc -//{ -//public: -// using algorithm = TAlgorithm; -// using accumulator_type = typename algorithm::accumulator_type; -// -// // -// // Update the accumulator with a new byte -// // -// void update(uint8_t value) -// { -// m_crc = table_impl::update(m_crc, value); -// } -// -// // -// // Extract the final value of the accumulator. -// // -// ETL_NODISCARD accumulator_type final() { return m_crc ^ algorithm::xor_out_value; } -// -// // -// // Reset the state of the accumulator back to the INITIAL value. -// // -// void reset() { m_crc = table_impl::make_initial_value(algorithm::initial_value); } -// -// -//private: -// using table_impl = crc_chunk_table; -// -// accumulator_type m_crc = table_impl::make_initial_value(algorithm::initial_value); -//}; \ No newline at end of file diff --git a/include/etl/experimental/crc_table_4.h b/include/etl/experimental/crc_table_4.h deleted file mode 100644 index a44bed84..00000000 --- a/include/etl/experimental/crc_table_4.h +++ /dev/null @@ -1,698 +0,0 @@ - -#pragma once - -#include -#include - -//***************************************************************************** -template -class entry -{ -private: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1))) != 0U; - -public: - - static const TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); -}; - -//***************************************************************************** -/// 8 bit chunks -//***************************************************************************** -template -class table_entry_8 -{ -//private: -public: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const size_t Shift_Bits = size_t(Accumulator_Bits - 8U); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value>::value>::value>::value>::value>::value>::value; -}; - -//***************************************************************************** -/// 4 bit chunks -//***************************************************************************** -template -class table_entry_4 -{ -private: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_4_Bits); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value>::value>::value; -}; - -//***************************************************************************** -/// 2 bit chunks -//***************************************************************************** -template -class table_entry_2 -{ -private: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_2_Bits); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value; -}; - -//***************************************************************************** -template -struct crc_table -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[256] = - { - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value - }; - - return table; - } -}; - -template -struct crc_table -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[16] = - { - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value - }; - - return table; - } -}; - -template -struct crc_table -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[4] = - { - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value - }; - - return table; - } -}; - - -// -// Define the CRC algorithm parameters -// -template -struct crc_algorithm -{ - using accumulator_type = TAccumulator; - static constexpr TAccumulator polynomial = Polynomial; - static constexpr TAccumulator initial_value = Initial; - static constexpr TAccumulator xor_out_value = Xor_Out; - static constexpr bool reverse = Reverse; -}; - -// -// Define the basic traits we use in our CRC accumulators and Table Lookup -// -template -struct crc_traits {}; - -template -struct crc_traits -{ - static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; - static constexpr std::size_t CHUNK_BITS = 2; - static constexpr uint8_t CHUNK_MASK = 0x03u; - static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; - - using table_type = std::array; -}; - -template -struct crc_traits -{ - static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; - static constexpr std::size_t CHUNK_BITS = 4; - static constexpr uint8_t CHUNK_MASK = 0x0Fu; - static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; - - using table_type = std::array; -}; - -template -struct crc_traits -{ - static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; - static constexpr std::size_t CHUNK_BITS = 8; - static constexpr uint8_t CHUNK_MASK = 0xFFu; - static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; - - using table_type = std::array; -}; - -// -// CRC rotation policies. -// -// Forward rotation means that we clock in data MSB->LSB and rotate the Accumulator register left -// Reverse rotation means that we clock in data LSB->MSB and rotate the Accumulator register right -// - -template -struct crc_forward_policy -{ - using traits = crc_traits; - - - [[nodiscard]] static constexpr TAccumulator update_impl_tiny( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_small( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_large( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value, table); // full byte - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_chunk( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - // ensure we have only 4 bits - value &= traits::CHUNK_MASK; - - // Extract the most significant nibble of the crc and xor with the value nibble - uint8_t t = (crc >> (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS)) ^ value; - - // special case for when chunk size is same as accumulator size. - if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { - // shit crc left the size of the nibble - crc <<= traits::CHUNK_BITS; - - // xor in the table data - crc ^= table[t]; - } - else { - crc = table[t]; - } - - return crc; - } - - [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) - { - // initialise with the register in the upper bits - TAccumulator entry = TAccumulator(index) << (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS); - - for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) - { - // We are processing MSBs / rotating left so we need to check the high bit - if (entry & (TAccumulator(1u) << (traits::ACCUMULATOR_BITS - 1))) { - entry = (entry << 1) ^ polynomial; - } - else { - entry = (entry << 1); - } - } - - return entry; - } - - [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) - { - return init; - } -}; - -template -struct crc_reverse_policy -{ - using traits = crc_traits; - - - [[nodiscard]] static constexpr TAccumulator update_impl_tiny( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_small( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble - crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_large( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value, table); // full byte - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_chunk( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - // ensure we have only 4 bits - value &= traits::CHUNK_MASK; - - // Extract the least significant nibble of the crc and xor with the value nibble - uint8_t t = (crc & traits::CHUNK_MASK) ^ value; - - // special case for when chunk size is same as accumulator size. - if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { - // shit crc right the size of a nibble - crc >>= traits::CHUNK_BITS; - - // xor in the table data - crc ^= table[t]; - } - else { - crc = table[t]; - } - - return crc; - } - - [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) - { - // initialise with the register in the lower bits - TAccumulator entry = TAccumulator(index); - - for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) - { - // we are processing LSBs/rotating right - if (entry & 0x1u) { - entry = (entry >> 1) ^ util::reverse_bits(polynomial); - } - else { - entry = (entry >> 1); - } - } - - return entry; - } - - [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) - { - return util::reverse_bits(init); - } -}; - - -// -// A generic CRC lookup table sized for computing a nibble (4 bits) at a time. -// -// This is can be a large reduction of table space storage for embedded devices. -// -template ::value>> -class crc_chunk_table -{ -public: - - using policy = typename std::conditional, crc_forward_policy>::type; - - using traits = typename policy::traits; - - - // update the given crc accumulator with the value - [[nodiscard]] static constexpr TAccumulator update(TAccumulator crc, uint8_t value) - { - if constexpr (Table_Size == size_t::tiny) { - return policy::update_impl_tiny(crc, value, m_Table); - } - else if constexpr (Table_Size == size_t::small) { - return policy::update_impl_small(crc, value, m_Table); - } - else if constexpr (Table_Size == size_t::large) { - return policy::update_impl_large(crc, value, m_Table); - } - else { - static_assert("Unknown size_t"); - } - } - - // the crc accumulator initial value may need to be modified by the policy - // to account for rotation direction - [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) - { - return policy::make_initial_value(init); - } - -private: - -}; - - -// -// The generic CRC accumulator that is table driven -// -template -class crc -{ -public: - using algorithm = TAlgorithm; - using accumulator_type = typename algorithm::accumulator_type; - - // - // Update the accumulator with a new byte - // - void update(uint8_t value) - { - m_crc = table_impl::update(m_crc, value); - } - - // - // Extract the final value of the accumulator. - // - [[nodiscard]] accumulator_type final() { return m_crc ^ algorithm::xor_out_value; } - - // - // Reset the state of the accumulator back to the INITIAL value. - // - void reset() { m_crc = table_impl::make_initial_value(algorithm::initial_value); } - - -private: - using table_impl = crc_chunk_table; - - accumulator_type m_crc = table_impl::make_initial_value(algorithm::initial_value); -}; \ No newline at end of file diff --git a/include/etl/experimental/crc_table_generator.h b/include/etl/experimental/crc_table_generator.h deleted file mode 100644 index 0d5c514a..00000000 --- a/include/etl/experimental/crc_table_generator.h +++ /dev/null @@ -1,712 +0,0 @@ - -#pragma once - -#include -#include - -enum -{ - Chunk_8_Bits = 8, - Chunk_4_Bits = 4, - Chunk_2_Bits = 2 -}; - -//***************************************************************************** -template -class entry -{ -private: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const bool Do_Poly = (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1U))) != 0U; - -public: - - static const TAccumulator value = TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); -}; - -//***************************************************************************** -template -class table_entry; - -//***************************************************************************** -/// 8 bit chunks -//***************************************************************************** -template -class table_entry -{ -//private: -public: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_8_Bits); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value>::value>::value>::value>::value>::value>::value; -}; - -//***************************************************************************** -/// 4 bit chunks -//***************************************************************************** -template -class table_entry -{ -private: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_4_Bits); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value>::value>::value; -}; - -//***************************************************************************** -/// 2 bit chunks -//***************************************************************************** -template -class table_entry -{ -private: - - static const size_t Accumulator_Bits = sizeof(TAccumulator) * CHAR_BIT; - static const size_t Shift_Bits = size_t(Accumulator_Bits - Chunk_2_Bits); - static const TAccumulator Entry = TAccumulator(Index << Shift_Bits); - -public: - - static const TAccumulator value = entry::value>::value; -}; - -//***************************************************************************** -template -struct crc_table; - -template -struct crc_table -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[256] = - { - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value - }; - - return table; - } -}; - -template -struct crc_table -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[16] = - { - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value - }; - - return table; - } -}; - -template -struct crc_table -{ - static const TAccumulator* get_table() - { - static const TAccumulator table[4] = - { - table_entry::value, - table_entry::value, - table_entry::value, - table_entry::value - }; - - return table; - } -}; - - -// -// Define the CRC algorithm parameters -// -template -struct crc_algorithm -{ - using accumulator_type = TAccumulator; - static constexpr TAccumulator polynomial = Polynomial; - static constexpr TAccumulator initial_value = Initial; - static constexpr TAccumulator xor_out_value = Xor_Out; - static constexpr bool reverse = Reverse; -}; - -// -// Define the basic traits we use in our CRC accumulators and Table Lookup -// -template -struct crc_traits {}; - -template -struct crc_traits -{ - static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; - static constexpr std::size_t CHUNK_BITS = 2; - static constexpr uint8_t CHUNK_MASK = 0x03u; - static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; - - using table_type = std::array; -}; - -template -struct crc_traits -{ - static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; - static constexpr std::size_t CHUNK_BITS = 4; - static constexpr uint8_t CHUNK_MASK = 0x0Fu; - static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; - - using table_type = std::array; -}; - -template -struct crc_traits -{ - static constexpr std::size_t ACCUMULATOR_BITS = sizeof(TAccumulator) * 8; - static constexpr std::size_t CHUNK_BITS = 8; - static constexpr uint8_t CHUNK_MASK = 0xFFu; - static constexpr std::size_t TABLE_ENTRIES = 1u << CHUNK_BITS; - - using table_type = std::array; -}; - -// -// CRC rotation policies. -// -// Forward rotation means that we clock in data MSB->LSB and rotate the Accumulator register left -// Reverse rotation means that we clock in data LSB->MSB and rotate the Accumulator register right -// - -template -struct crc_forward_policy -{ - using traits = crc_traits; - - - [[nodiscard]] static constexpr TAccumulator update_impl_tiny( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_small( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_large( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value, table); // full byte - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_chunk( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - // ensure we have only 4 bits - value &= traits::CHUNK_MASK; - - // Extract the most significant nibble of the crc and xor with the value nibble - uint8_t t = (crc >> (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS)) ^ value; - - // special case for when chunk size is same as accumulator size. - if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { - // shit crc left the size of the nibble - crc <<= traits::CHUNK_BITS; - - // xor in the table data - crc ^= table[t]; - } - else { - crc = table[t]; - } - - return crc; - } - - [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) - { - // initialise with the register in the upper bits - TAccumulator entry = TAccumulator(index) << (traits::ACCUMULATOR_BITS - traits::CHUNK_BITS); - - for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) - { - // We are processing MSBs / rotating left so we need to check the high bit - if (entry & (TAccumulator(1u) << (traits::ACCUMULATOR_BITS - 1))) { - entry = (entry << 1) ^ polynomial; - } - else { - entry = (entry << 1); - } - } - - return entry; - } - - [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) - { - return init; - } -}; - -template -struct crc_reverse_policy -{ - using traits = crc_traits; - - - [[nodiscard]] static constexpr TAccumulator update_impl_tiny( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low chunk - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 1)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 2)) & traits::CHUNK_MASK, table); - crc = update_chunk(crc, (value >> (traits::CHUNK_BITS * 3)) & traits::CHUNK_MASK, table); // high chunk - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_small( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value & traits::CHUNK_MASK, table); // low nibble - crc = update_chunk(crc, value >> traits::CHUNK_BITS, table); // high nibble - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_impl_large( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - crc = update_chunk(crc, value, table); // full byte - return crc; - } - - [[nodiscard]] static constexpr TAccumulator update_chunk( - TAccumulator crc, uint8_t value, typename traits::table_type const& table) - { - // ensure we have only 4 bits - value &= traits::CHUNK_MASK; - - // Extract the least significant nibble of the crc and xor with the value nibble - uint8_t t = (crc & traits::CHUNK_MASK) ^ value; - - // special case for when chunk size is same as accumulator size. - if constexpr (traits::ACCUMULATOR_BITS > traits::CHUNK_BITS) { - // shit crc right the size of a nibble - crc >>= traits::CHUNK_BITS; - - // xor in the table data - crc ^= table[t]; - } - else { - crc = table[t]; - } - - return crc; - } - - [[nodiscard]] static constexpr TAccumulator generate_entry(TAccumulator const polynomial, uint8_t const index) - { - // initialise with the register in the lower bits - TAccumulator entry = TAccumulator(index); - - for (std::size_t i = 0; i < traits::CHUNK_BITS; i++) - { - // we are processing LSBs/rotating right - if (entry & 0x1u) { - entry = (entry >> 1) ^ util::reverse_bits(polynomial); - } - else { - entry = (entry >> 1); - } - } - - return entry; - } - - [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) - { - return util::reverse_bits(init); - } -}; - - -// -// A generic CRC lookup table sized for computing a nibble (4 bits) at a time. -// -// This is can be a large reduction of table space storage for embedded devices. -// -template ::value>> -class crc_chunk_table -{ -public: - - using policy = typename std::conditional, crc_forward_policy>::type; - - using traits = typename policy::traits; - - - // update the given crc accumulator with the value - [[nodiscard]] static constexpr TAccumulator update(TAccumulator crc, uint8_t value) - { - if constexpr (Table_Size == size_t::tiny) { - return policy::update_impl_tiny(crc, value, m_Table); - } - else if constexpr (Table_Size == size_t::small) { - return policy::update_impl_small(crc, value, m_Table); - } - else if constexpr (Table_Size == size_t::large) { - return policy::update_impl_large(crc, value, m_Table); - } - else { - static_assert("Unknown size_t"); - } - } - - // the crc accumulator initial value may need to be modified by the policy - // to account for rotation direction - [[nodiscard]] static constexpr TAccumulator make_initial_value(TAccumulator init) - { - return policy::make_initial_value(init); - } - -private: - -}; - - -// -// The generic CRC accumulator that is table driven -// -template -class crc -{ -public: - using algorithm = TAlgorithm; - using accumulator_type = typename algorithm::accumulator_type; - - // - // Update the accumulator with a new byte - // - void update(uint8_t value) - { - m_crc = table_impl::update(m_crc, value); - } - - // - // Extract the final value of the accumulator. - // - [[nodiscard]] accumulator_type final() { return m_crc ^ algorithm::xor_out_value; } - - // - // Reset the state of the accumulator back to the INITIAL value. - // - void reset() { m_crc = table_impl::make_initial_value(algorithm::initial_value); } - - -private: - using table_impl = crc_chunk_table; - - accumulator_type m_crc = table_impl::make_initial_value(algorithm::initial_value); -}; \ No newline at end of file diff --git a/include/etl/private/crc16_poly_0x1021_.h b/include/etl/private/crc16_poly_0x1021_.h deleted file mode 100644 index 85fc83d0..00000000 --- a/include/etl/private/crc16_poly_0x1021_.h +++ /dev/null @@ -1,191 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2019 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef ETL_CRC16_POLY_0X1021_INCLUDED -#define ETL_CRC16_POLY_0X1021_INCLUDED - -#include - -#include "../platform.h" -#include "../frame_check_sequence.h" -#include "../binary.h" -#include "../iterator.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_ccitt 16 bit CRC Poly 0x1021 calculation -///\ingroup crc - -namespace etl -{ - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc16_table_poly_0x1021 - { - public: - - //************************************************************************* - uint16_t add(uint16_t crc, uint8_t value) const - { - static const uint16_t table[256] = - { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, - 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, - 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, - 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, - 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, - 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, - 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, - 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, - 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 - }; - - return (crc << 8) ^ table[((crc >> 8) ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc16_table_poly_0x1021_reflected - { - public: - - //************************************************************************* - uint16_t add(uint16_t crc, uint8_t value) const - { - static const uint16_t table[256] = - { - 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, - 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876, - 0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD, 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5, - 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C, 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974, - 0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB, 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3, - 0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A, 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72, - 0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9, 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1, - 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738, 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70, - 0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7, 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF, - 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036, 0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E, - 0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5, 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD, - 0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134, 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C, - 0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB, - 0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232, 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A, - 0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1, 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9, - 0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78 - }; - - return (crc >> 8) ^ table[(crc ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// CRC16 Poly 0x1021 policy. - /// Calculates CRC16 using polynomial 0x1021 - //*************************************************************************** - template - struct crc16_policy_poly_0x1021 : public crc16_table_poly_0x1021 - { - typedef uint16_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint16_t initial() const - { - return INITIAL; - } - - //************************************************************************* - inline uint16_t final(uint16_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //*************************************************************************** - /// CRC16 Poly 0x1021 reflected policy specialisation. - //*************************************************************************** - template - struct crc16_policy_poly_0x1021 : public crc16_table_poly_0x1021_reflected - { - typedef uint16_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint16_t initial() const - { - return INITIAL; - } - - //************************************************************************* - uint16_t final(uint16_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //************************************************************************* - /// CRC16 Poly 0x1021 - //************************************************************************* - template - class crc16_poly_0x1021 : public etl::frame_check_sequence > - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc16_poly_0x1021() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc16_poly_0x1021(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; -} - -#endif diff --git a/include/etl/private/crc16_poly_0x8005.h b/include/etl/private/crc16_poly_0x8005.h deleted file mode 100644 index 14526ff5..00000000 --- a/include/etl/private/crc16_poly_0x8005.h +++ /dev/null @@ -1,191 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2018 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef ETL_CRC16_POLY_0X8005_INCLUDED -#define ETL_CRC16_POLY_0X8005_INCLUDED - -#include - -#include "../platform.h" -#include "../frame_check_sequence.h" -#include "../binary.h" -#include "../iterator.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc16_ccitt 16 bit CRC Poly 0x8005 calculation -///\ingroup crc - -namespace etl -{ - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc16_table_poly_0x8005 - { - public: - - //************************************************************************* - uint16_t add(uint16_t crc, uint8_t value) const - { - static const uint16_t table[256] = - { - 0x0000, 0x8005, 0x800F, 0x000A, 0x801B, 0x001E, 0x0014, 0x8011, 0x8033, 0x0036, 0x003C, 0x8039, 0x0028, 0x802D, 0x8027, 0x0022, - 0x8063, 0x0066, 0x006C, 0x8069, 0x0078, 0x807D, 0x8077, 0x0072, 0x0050, 0x8055, 0x805F, 0x005A, 0x804B, 0x004E, 0x0044, 0x8041, - 0x80C3, 0x00C6, 0x00CC, 0x80C9, 0x00D8, 0x80DD, 0x80D7, 0x00D2, 0x00F0, 0x80F5, 0x80FF, 0x00FA, 0x80EB, 0x00EE, 0x00E4, 0x80E1, - 0x00A0, 0x80A5, 0x80AF, 0x00AA, 0x80BB, 0x00BE, 0x00B4, 0x80B1, 0x8093, 0x0096, 0x009C, 0x8099, 0x0088, 0x808D, 0x8087, 0x0082, - 0x8183, 0x0186, 0x018C, 0x8189, 0x0198, 0x819D, 0x8197, 0x0192, 0x01B0, 0x81B5, 0x81BF, 0x01BA, 0x81AB, 0x01AE, 0x01A4, 0x81A1, - 0x01E0, 0x81E5, 0x81EF, 0x01EA, 0x81FB, 0x01FE, 0x01F4, 0x81F1, 0x81D3, 0x01D6, 0x01DC, 0x81D9, 0x01C8, 0x81CD, 0x81C7, 0x01C2, - 0x0140, 0x8145, 0x814F, 0x014A, 0x815B, 0x015E, 0x0154, 0x8151, 0x8173, 0x0176, 0x017C, 0x8179, 0x0168, 0x816D, 0x8167, 0x0162, - 0x8123, 0x0126, 0x012C, 0x8129, 0x0138, 0x813D, 0x8137, 0x0132, 0x0110, 0x8115, 0x811F, 0x011A, 0x810B, 0x010E, 0x0104, 0x8101, - 0x8303, 0x0306, 0x030C, 0x8309, 0x0318, 0x831D, 0x8317, 0x0312, 0x0330, 0x8335, 0x833F, 0x033A, 0x832B, 0x032E, 0x0324, 0x8321, - 0x0360, 0x8365, 0x836F, 0x036A, 0x837B, 0x037E, 0x0374, 0x8371, 0x8353, 0x0356, 0x035C, 0x8359, 0x0348, 0x834D, 0x8347, 0x0342, - 0x03C0, 0x83C5, 0x83CF, 0x03CA, 0x83DB, 0x03DE, 0x03D4, 0x83D1, 0x83F3, 0x03F6, 0x03FC, 0x83F9, 0x03E8, 0x83ED, 0x83E7, 0x03E2, - 0x83A3, 0x03A6, 0x03AC, 0x83A9, 0x03B8, 0x83BD, 0x83B7, 0x03B2, 0x0390, 0x8395, 0x839F, 0x039A, 0x838B, 0x038E, 0x0384, 0x8381, - 0x0280, 0x8285, 0x828F, 0x028A, 0x829B, 0x029E, 0x0294, 0x8291, 0x82B3, 0x02B6, 0x02BC, 0x82B9, 0x02A8, 0x82AD, 0x82A7, 0x02A2, - 0x82E3, 0x02E6, 0x02EC, 0x82E9, 0x02F8, 0x82FD, 0x82F7, 0x02F2, 0x02D0, 0x82D5, 0x82DF, 0x02DA, 0x82CB, 0x02CE, 0x02C4, 0x82C1, - 0x8243, 0x0246, 0x024C, 0x8249, 0x0258, 0x825D, 0x8257, 0x0252, 0x0270, 0x8275, 0x827F, 0x027A, 0x826B, 0x026E, 0x0264, 0x8261, - 0x0220, 0x8225, 0x822F, 0x022A, 0x823B, 0x023E, 0x0234, 0x8231, 0x8213, 0x0216, 0x021C, 0x8219, 0x0208, 0x820D, 0x8207, 0x0202 - }; - - return (crc << 8) ^ table[((crc >> 8) ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc16_table_poly_0x8005_reflected - { - public: - - //************************************************************************* - uint16_t add(uint16_t crc, uint8_t value) const - { - static const uint16_t table[256] = - { - 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, - 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, - 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, - 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, - 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, - 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, - 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, - 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, - 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, - 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, - 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, - 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, - 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, - 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, - 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, - 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 - }; - - return (crc >> 8) ^ table[(crc ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// CRC16 Poly 0x8005 policy. - /// Calculates CRC16 using polynomial 0x8005 - //*************************************************************************** - template - struct crc16_policy_poly_0x8005 : public crc16_table_poly_0x8005 - { - typedef uint16_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint16_t initial() const - { - return INITIAL; - } - - //************************************************************************* - inline uint16_t final(uint16_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //*************************************************************************** - /// CRC16 Poly 0x8005 reflected policy. - //*************************************************************************** - template - struct crc16_policy_poly_0x8005< INITIAL, XOR_OUT, true> : public crc16_table_poly_0x8005_reflected - { - typedef uint16_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint16_t initial() const - { - return INITIAL; - } - - //************************************************************************* - inline uint16_t final(uint16_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //************************************************************************* - /// CRC16 Poly 0x8005 - //************************************************************************* - template - class crc16_poly_0x8005 : public etl::frame_check_sequence > - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc16_poly_0x8005() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc16_poly_0x8005(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; -} - -#endif diff --git a/include/etl/private/crc32_poly_0x04c11db7.h b/include/etl/private/crc32_poly_0x04c11db7.h deleted file mode 100644 index 801e70e8..00000000 --- a/include/etl/private/crc32_poly_0x04c11db7.h +++ /dev/null @@ -1,191 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2018 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef ETL_CRC16_TABLE_POLY_0X04C11DB7_INCLUDED -#define ETL_CRC16_TABLE_POLY_0X04C11DB7_INCLUDED - -#include - -#include "../platform.h" -#include "../frame_check_sequence.h" -#include "../binary.h" -#include "../iterator.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc32_poly 0x04C11DB7 32 bit CRC Poly 0x04C11DB7 calculation -///\ingroup crc - -namespace etl -{ - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc32_table_poly_0x04c11db7 - { - public: - - //************************************************************************* - uint32_t add(uint32_t crc, uint8_t value) const - { - static const uint32_t table[256] = - { - 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, - 0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75, 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3, 0x709F7B7A, 0x745E66CD, - 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039, 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58, 0xBAEA46EF, 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D, - 0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB, 0xCEB42022, 0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1, 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, - 0x34867077, 0x30476DC0, 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072, 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4, 0x0808D07D, 0x0CC9CDCA, - 0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE, 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08, 0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA, - 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, 0xBB60ADFC, 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6, 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A, - 0xE0B41DE7, 0xE4750050, 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2, 0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34, 0xDC3ABDED, 0xD8FBA05A, - 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637, 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 0x4F040D56, 0x4BC510E1, 0x46863638, 0x42472B8F, 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53, - 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5, 0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF, 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, - 0xF12F560E, 0xF5EE4BB9, 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B, 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD, 0xCDA1F604, 0xC960EBB3, - 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7, 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71, 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3, - 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2, 0x470CDD2B, 0x43CDC09C, 0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8, 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, - 0x119B4BE9, 0x155A565E, 0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC, 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, 0x2056CD3A, 0x2D15EBE3, 0x29D4F654, - 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0, 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676, 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4, - 0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662, 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4 - }; - - return (crc << 8) ^ table[((crc >> 24) ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc32_table_poly_0x04c11db7_reflected - { - public: - - //************************************************************************* - uint32_t add(uint32_t crc, uint8_t value) const - { - static const uint32_t table[256] = - { - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, - 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, - 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, - 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, - 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, - 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, - 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, - 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, - 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, - 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, - 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, - 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, - 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, - 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, - 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D - }; - - return (crc >> 8) ^ table[(crc ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// CRC32 Poly 0x04C11DB7 policy. - /// Calculates CRC32 using polynomial 0x04C11DB7 - //*************************************************************************** - template - struct crc32_policy_poly_0x04c11db7 : public crc32_table_poly_0x04c11db7 - { - typedef uint32_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint32_t initial() const - { - return INITIAL; - } - - //************************************************************************* - uint32_t final(uint32_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //*************************************************************************** - /// CRC32 Poly 0x04C11DB7 reflected policy specialisation. - //*************************************************************************** - template - struct crc32_policy_poly_0x04c11db7 : public crc32_table_poly_0x04c11db7_reflected - { - typedef uint32_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint32_t initial() const - { - return INITIAL; - } - - //************************************************************************* - uint32_t final(uint32_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //************************************************************************* - /// CRC32 Poly 0x04C11DB7 - //************************************************************************* - template - class crc32_poly_0x04c11db7 : public etl::frame_check_sequence > - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc32_poly_0x04c11db7() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc32_poly_0x04c11db7(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; -} - -#endif diff --git a/include/etl/private/crc32_poly_0x1edc6f41.h b/include/etl/private/crc32_poly_0x1edc6f41.h deleted file mode 100644 index a1e9677c..00000000 --- a/include/etl/private/crc32_poly_0x1edc6f41.h +++ /dev/null @@ -1,191 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2019 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef ETL_CRC16_TABLE_POLY_0X1EDC6F41_INCLUDED -#define ETL_CRC16_TABLE_POLY_0X1EDC6F41_INCLUDED - -#include - -#include "../platform.h" -#include "../frame_check_sequence.h" -#include "../binary.h" -#include "../iterator.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc32_poly 0x1EDC6F41 32 bit CRC Poly 0x1EDC6F41 calculation -///\ingroup crc - -namespace etl -{ - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc32_table_poly_0x1edc6f41 - { - public: - - //************************************************************************* - uint32_t add(uint32_t crc, uint8_t value) const - { - static const uint32_t table[256] = - { - 0x00000000, 0xC0C1D64F, 0xEF0EDC87, 0x2FCF0AC8, 0xF8E959E3, 0x38288FAC, 0x17E78564, 0xD726532B, 0xF31A9B51, 0x33DB4D1E, 0x1C1447D6, 0xDCD59199, 0x0BF3C2B2, 0xCB3214FD, 0xE4FD1E35, 0x243CC87A, - 0xF6E37A08, 0x3622AC47, 0x19EDA68F, 0xD92C70C0, 0x0E0A23EB, 0xCECBF5A4, 0xE104FF6C, 0x21C52923, 0x05F9E159, 0xC5383716, 0xEAF73DDE, 0x2A36EB91, 0xFD10B8BA, 0x3DD16EF5, 0x121E643D, 0xD2DFB272, - 0x7B71BD04, 0xBBB06B4B, 0x947F6183, 0x54BEB7CC, 0x8398E4E7, 0x435932A8, 0x6C963860, 0xAC57EE2F, 0x886B2655, 0x48AAF01A, 0x6765FAD2, 0xA7A42C9D, 0x70827FB6, 0xB043A9F9, 0x9F8CA331, 0x5F4D757E, - 0x8D92C70C, 0x4D531143, 0x629C1B8B, 0xA25DCDC4, 0x757B9EEF, 0xB5BA48A0, 0x9A754268, 0x5AB49427, 0x7E885C5D, 0xBE498A12, 0x918680DA, 0x51475695, 0x866105BE, 0x46A0D3F1, 0x696FD939, 0xA9AE0F76, - 0x3DB8DE82, 0xFD7908CD, 0xD2B60205, 0x1277D44A, 0xC5518761, 0x0590512E, 0x2A5F5BE6, 0xEA9E8DA9, 0xCEA245D3, 0x0E63939C, 0x21AC9954, 0xE16D4F1B, 0x364B1C30, 0xF68ACA7F, 0xD945C0B7, 0x198416F8, - 0xCB5BA48A, 0x0B9A72C5, 0x2455780D, 0xE494AE42, 0x33B2FD69, 0xF3732B26, 0xDCBC21EE, 0x1C7DF7A1, 0x38413FDB, 0xF880E994, 0xD74FE35C, 0x178E3513, 0xC0A86638, 0x0069B077, 0x2FA6BABF, 0xEF676CF0, - 0x46C96386, 0x8608B5C9, 0xA9C7BF01, 0x6906694E, 0xBE203A65, 0x7EE1EC2A, 0x512EE6E2, 0x91EF30AD, 0xB5D3F8D7, 0x75122E98, 0x5ADD2450, 0x9A1CF21F, 0x4D3AA134, 0x8DFB777B, 0xA2347DB3, 0x62F5ABFC, - 0xB02A198E, 0x70EBCFC1, 0x5F24C509, 0x9FE51346, 0x48C3406D, 0x88029622, 0xA7CD9CEA, 0x670C4AA5, 0x433082DF, 0x83F15490, 0xAC3E5E58, 0x6CFF8817, 0xBBD9DB3C, 0x7B180D73, 0x54D707BB, 0x9416D1F4, - 0x1EDC6F41, 0xDE1DB90E, 0xF1D2B3C6, 0x31136589, 0xE63536A2, 0x26F4E0ED, 0x093BEA25, 0xC9FA3C6A, 0xEDC6F410, 0x2D07225F, 0x02C82897, 0xC209FED8, 0x152FADF3, 0xD5EE7BBC, 0xFA217174, 0x3AE0A73B, - 0xE83F1549, 0x28FEC306, 0x0731C9CE, 0xC7F01F81, 0x10D64CAA, 0xD0179AE5, 0xFFD8902D, 0x3F194662, 0x1B258E18, 0xDBE45857, 0xF42B529F, 0x34EA84D0, 0xE3CCD7FB, 0x230D01B4, 0x0CC20B7C, 0xCC03DD33, - 0x65ADD245, 0xA56C040A, 0x8AA30EC2, 0x4A62D88D, 0x9D448BA6, 0x5D855DE9, 0x724A5721, 0xB28B816E, 0x96B74914, 0x56769F5B, 0x79B99593, 0xB97843DC, 0x6E5E10F7, 0xAE9FC6B8, 0x8150CC70, 0x41911A3F, - 0x934EA84D, 0x538F7E02, 0x7C4074CA, 0xBC81A285, 0x6BA7F1AE, 0xAB6627E1, 0x84A92D29, 0x4468FB66, 0x6054331C, 0xA095E553, 0x8F5AEF9B, 0x4F9B39D4, 0x98BD6AFF, 0x587CBCB0, 0x77B3B678, 0xB7726037, - 0x2364B1C3, 0xE3A5678C, 0xCC6A6D44, 0x0CABBB0B, 0xDB8DE820, 0x1B4C3E6F, 0x348334A7, 0xF442E2E8, 0xD07E2A92, 0x10BFFCDD, 0x3F70F615, 0xFFB1205A, 0x28977371, 0xE856A53E, 0xC799AFF6, 0x075879B9, - 0xD587CBCB, 0x15461D84, 0x3A89174C, 0xFA48C103, 0x2D6E9228, 0xEDAF4467, 0xC2604EAF, 0x02A198E0, 0x269D509A, 0xE65C86D5, 0xC9938C1D, 0x09525A52, 0xDE740979, 0x1EB5DF36, 0x317AD5FE, 0xF1BB03B1, - 0x58150CC7, 0x98D4DA88, 0xB71BD040, 0x77DA060F, 0xA0FC5524, 0x603D836B, 0x4FF289A3, 0x8F335FEC, 0xAB0F9796, 0x6BCE41D9, 0x44014B11, 0x84C09D5E, 0x53E6CE75, 0x9327183A, 0xBCE812F2, 0x7C29C4BD, - 0xAEF676CF, 0x6E37A080, 0x41F8AA48, 0x81397C07, 0x561F2F2C, 0x96DEF963, 0xB911F3AB, 0x79D025E4, 0x5DECED9E, 0x9D2D3BD1, 0xB2E23119, 0x7223E756, 0xA505B47D, 0x65C46232, 0x4A0B68FA, 0x8ACABEB5 - }; - - return (crc << 8) ^ table[((crc >> 24) ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc32_table_poly_0x1edc6f41_reflected - { - public: - - //************************************************************************* - uint32_t add(uint32_t crc, uint8_t value) const - { - static const uint32_t table[256] = - { - 0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, 0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB, 0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B, 0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24, - 0x105EC76F, 0xE235446C, 0xF165B798, 0x030E349B, 0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384, 0x9A879FA0, 0x68EC1CA3, 0x7BBCEF57, 0x89D76C54, 0x5D1D08BF, 0xAF768BBC, 0xBC267848, 0x4E4DFB4B, - 0x20BD8EDE, 0xD2D60DDD, 0xC186FE29, 0x33ED7D2A, 0xE72719C1, 0x154C9AC2, 0x061C6936, 0xF477EA35, 0xAA64D611, 0x580F5512, 0x4B5FA6E6, 0xB93425E5, 0x6DFE410E, 0x9F95C20D, 0x8CC531F9, 0x7EAEB2FA, - 0x30E349B1, 0xC288CAB2, 0xD1D83946, 0x23B3BA45, 0xF779DEAE, 0x05125DAD, 0x1642AE59, 0xE4292D5A, 0xBA3A117E, 0x4851927D, 0x5B016189, 0xA96AE28A, 0x7DA08661, 0x8FCB0562, 0x9C9BF696, 0x6EF07595, - 0x417B1DBC, 0xB3109EBF, 0xA0406D4B, 0x522BEE48, 0x86E18AA3, 0x748A09A0, 0x67DAFA54, 0x95B17957, 0xCBA24573, 0x39C9C670, 0x2A993584, 0xD8F2B687, 0x0C38D26C, 0xFE53516F, 0xED03A29B, 0x1F682198, - 0x5125DAD3, 0xA34E59D0, 0xB01EAA24, 0x42752927, 0x96BF4DCC, 0x64D4CECF, 0x77843D3B, 0x85EFBE38, 0xDBFC821C, 0x2997011F, 0x3AC7F2EB, 0xC8AC71E8, 0x1C661503, 0xEE0D9600, 0xFD5D65F4, 0x0F36E6F7, - 0x61C69362, 0x93AD1061, 0x80FDE395, 0x72966096, 0xA65C047D, 0x5437877E, 0x4767748A, 0xB50CF789, 0xEB1FCBAD, 0x197448AE, 0x0A24BB5A, 0xF84F3859, 0x2C855CB2, 0xDEEEDFB1, 0xCDBE2C45, 0x3FD5AF46, - 0x7198540D, 0x83F3D70E, 0x90A324FA, 0x62C8A7F9, 0xB602C312, 0x44694011, 0x5739B3E5, 0xA55230E6, 0xFB410CC2, 0x092A8FC1, 0x1A7A7C35, 0xE811FF36, 0x3CDB9BDD, 0xCEB018DE, 0xDDE0EB2A, 0x2F8B6829, - 0x82F63B78, 0x709DB87B, 0x63CD4B8F, 0x91A6C88C, 0x456CAC67, 0xB7072F64, 0xA457DC90, 0x563C5F93, 0x082F63B7, 0xFA44E0B4, 0xE9141340, 0x1B7F9043, 0xCFB5F4A8, 0x3DDE77AB, 0x2E8E845F, 0xDCE5075C, - 0x92A8FC17, 0x60C37F14, 0x73938CE0, 0x81F80FE3, 0x55326B08, 0xA759E80B, 0xB4091BFF, 0x466298FC, 0x1871A4D8, 0xEA1A27DB, 0xF94AD42F, 0x0B21572C, 0xDFEB33C7, 0x2D80B0C4, 0x3ED04330, 0xCCBBC033, - 0xA24BB5A6, 0x502036A5, 0x4370C551, 0xB11B4652, 0x65D122B9, 0x97BAA1BA, 0x84EA524E, 0x7681D14D, 0x2892ED69, 0xDAF96E6A, 0xC9A99D9E, 0x3BC21E9D, 0xEF087A76, 0x1D63F975, 0x0E330A81, 0xFC588982, - 0xB21572C9, 0x407EF1CA, 0x532E023E, 0xA145813D, 0x758FE5D6, 0x87E466D5, 0x94B49521, 0x66DF1622, 0x38CC2A06, 0xCAA7A905, 0xD9F75AF1, 0x2B9CD9F2, 0xFF56BD19, 0x0D3D3E1A, 0x1E6DCDEE, 0xEC064EED, - 0xC38D26C4, 0x31E6A5C7, 0x22B65633, 0xD0DDD530, 0x0417B1DB, 0xF67C32D8, 0xE52CC12C, 0x1747422F, 0x49547E0B, 0xBB3FFD08, 0xA86F0EFC, 0x5A048DFF, 0x8ECEE914, 0x7CA56A17, 0x6FF599E3, 0x9D9E1AE0, - 0xD3D3E1AB, 0x21B862A8, 0x32E8915C, 0xC083125F, 0x144976B4, 0xE622F5B7, 0xF5720643, 0x07198540, 0x590AB964, 0xAB613A67, 0xB831C993, 0x4A5A4A90, 0x9E902E7B, 0x6CFBAD78, 0x7FAB5E8C, 0x8DC0DD8F, - 0xE330A81A, 0x115B2B19, 0x020BD8ED, 0xF0605BEE, 0x24AA3F05, 0xD6C1BC06, 0xC5914FF2, 0x37FACCF1, 0x69E9F0D5, 0x9B8273D6, 0x88D28022, 0x7AB90321, 0xAE7367CA, 0x5C18E4C9, 0x4F48173D, 0xBD23943E, - 0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81, 0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E, 0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E, 0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351 - }; - - return (crc >> 8) ^ table[(crc ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// CRC32 Poly 0x1EDC6F41 policy. - /// Calculates CRC32 using polynomial 0x1EDC6F41 - //*************************************************************************** - template - struct crc32_policy_poly_0x1edc6f41 : public crc32_table_poly_0x1edc6f41 - { - typedef uint32_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint32_t initial() const - { - return INITIAL; - } - - //************************************************************************* - uint32_t final(uint32_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //*************************************************************************** - /// CRC32 Poly 0x1EDC6F41 reflected policy specialisation. - //*************************************************************************** - template - struct crc32_policy_poly_0x1edc6f41 : public crc32_table_poly_0x1edc6f41_reflected - { - typedef uint32_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint32_t initial() const - { - return INITIAL; - } - - //************************************************************************* - uint32_t final(uint32_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //************************************************************************* - /// CRC32 Poly 0x1EDC6F41 - //************************************************************************* - template - class crc32_poly_0x1edc6f41 : public etl::frame_check_sequence > - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc32_poly_0x1edc6f41() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc32_poly_0x1edc6f41(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; -} - -#endif diff --git a/include/etl/private/crc64_poly_0x42f0e1eba9ea3693.h b/include/etl/private/crc64_poly_0x42f0e1eba9ea3693.h deleted file mode 100644 index 1237c002..00000000 --- a/include/etl/private/crc64_poly_0x42f0e1eba9ea3693.h +++ /dev/null @@ -1,223 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2019 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef ETL_CRC16_TABLE_POLY_0X42F0E1EBA9EA3693_INCLUDED -#define ETL_CRC16_TABLE_POLY_0X42F0E1EBA9EA3693_INCLUDED - -#include - -#include "../platform.h" -#include "../frame_check_sequence.h" -#include "../binary.h" -#include "../iterator.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc64_poly 0x42F0E1EBA9EA3693 64 bit CRC Poly 0x42F0E1EBA9EA3693 calculation -///\ingroup crc - -namespace etl -{ - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc64_table_poly_0x42f0e1eba9ea3693 - { - public: - - //************************************************************************* - uint64_t add(uint64_t crc, uint8_t value) const - { - static const uint64_t table[256] = - { - 0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, 0x493366450E42ECDF, 0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A, - 0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B, 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4, - 0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A, 0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285, - 0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4, 0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B, - 0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0x0B6BD3C3DBFD506B, 0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4, - 0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5, 0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A, - 0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584, 0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B, - 0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A, 0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5, - 0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A, 0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645, - 0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324, 0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB, - 0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75, 0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA, - 0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB, 0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14, - 0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144, 0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B, - 0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA, 0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0x0A3B7B1923564425, - 0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB, 0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874, - 0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15, 0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA, - 0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78, 0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7, - 0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6, 0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19, - 0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97, 0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648, - 0x02A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329, 0x4B9237F0FF14C443, 0x0962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6, - 0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6, 0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879, - 0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18, 0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7, - 0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149, 0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96, - 0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x09CA82762AAB78F7, 0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x020905D88D03A2BB, 0x40F9E43324E99428, - 0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57, 0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288, - 0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9, 0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36, - 0x4AC29F2A07BFD00D, 0x08327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8, 0x03F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767, - 0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206, 0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9, - 0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589, 0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956, - 0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37, 0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8, - 0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x0359AD0275A8B6F5, 0x41A94CE9DC428066, 0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x089A2AACD2006CB9, - 0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8, 0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507 - }; - - return (crc << 8) ^ table[((crc >> 56) ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// Table and add value. - //*************************************************************************** - class crc64_table_poly_0x42f0e1eba9ea3693_reflected - { - public: - - //************************************************************************* - uint64_t add(uint64_t crc, uint8_t value) const - { - static const uint64_t table[256] = - { - 0x0000000000000000, 0xC96C5795D7870F42, 0x64B62BCAEBC387A1, 0xADDA7C5F3C4488E3, 0xFB374270A266CC92, 0x325B15E575E1C3D0, 0x9F8169BA49A54B33, 0x56ED3E2F9E224471, - 0x7D9BA13851336649, 0xB4F7F6AD86B4690B, 0x192D8AF2BAF0E1E8, 0xD041DD676D77EEAA, 0x86ACE348F355AADB, 0x4FC0B4DD24D2A599, 0xE21AC88218962D7A, 0x2B769F17CF112238, - 0xF7A18709FF1EBC66, 0x3ECDD09C2899B324, 0x9317ACC314DD3BC7, 0x5A7BFB56C35A3485, 0x0C96C5795D7870F4, 0xC5FA92EC8AFF7FB6, 0x6820EEB3B6BBF755, 0xA14CB926613CF817, - 0x8A3A2631AE2DDA2F, 0x435671A479AAD56D, 0xEE8C0DFB45EE5D8E, 0x27E05A6E926952CC, 0x710D64410C4B16BD, 0xB86133D4DBCC19FF, 0x15BB4F8BE788911C, 0xDCD7181E300F9E5E, - 0x7BD0C384FF8F5E33, 0xB2BC941128085171, 0x1F66E84E144CD992, 0xD60ABFDBC3CBD6D0, 0x80E781F45DE992A1, 0x498BD6618A6E9DE3, 0xE451AA3EB62A1500, 0x2D3DFDAB61AD1A42, - 0x064B62BCAEBC387A, 0xCF273529793B3738, 0x62FD4976457FBFDB, 0xAB911EE392F8B099, 0xFD7C20CC0CDAF4E8, 0x34107759DB5DFBAA, 0x99CA0B06E7197349, 0x50A65C93309E7C0B, - 0x8C71448D0091E255, 0x451D1318D716ED17, 0xE8C76F47EB5265F4, 0x21AB38D23CD56AB6, 0x774606FDA2F72EC7, 0xBE2A516875702185, 0x13F02D374934A966, 0xDA9C7AA29EB3A624, - 0xF1EAE5B551A2841C, 0x3886B22086258B5E, 0x955CCE7FBA6103BD, 0x5C3099EA6DE60CFF, 0x0ADDA7C5F3C4488E, 0xC3B1F050244347CC, 0x6E6B8C0F1807CF2F, 0xA707DB9ACF80C06D, - 0xF4843657A840A05B, 0x3DE861C27FC7AF19, 0x90321D9D438327FA, 0x595E4A08940428B8, 0x0FB374270A266CC9, 0xC6DF23B2DDA1638B, 0x6B055FEDE1E5EB68, 0xA26908783662E42A, - 0x891F976FF973C612, 0x4073C0FA2EF4C950, 0xEDA9BCA512B041B3, 0x24C5EB30C5374EF1, 0x7228D51F5B150A80, 0xBB44828A8C9205C2, 0x169EFED5B0D68D21, 0xDFF2A94067518263, - 0x0325B15E575E1C3D, 0xCA49E6CB80D9137F, 0x67939A94BC9D9B9C, 0xAEFFCD016B1A94DE, 0xF812F32EF538D0AF, 0x317EA4BB22BFDFED, 0x9CA4D8E41EFB570E, 0x55C88F71C97C584C, - 0x7EBE1066066D7A74, 0xB7D247F3D1EA7536, 0x1A083BACEDAEFDD5, 0xD3646C393A29F297, 0x85895216A40BB6E6, 0x4CE50583738CB9A4, 0xE13F79DC4FC83147, 0x28532E49984F3E05, - 0x8F54F5D357CFFE68, 0x4638A2468048F12A, 0xEBE2DE19BC0C79C9, 0x228E898C6B8B768B, 0x7463B7A3F5A932FA, 0xBD0FE036222E3DB8, 0x10D59C691E6AB55B, 0xD9B9CBFCC9EDBA19, - 0xF2CF54EB06FC9821, 0x3BA3037ED17B9763, 0x96797F21ED3F1F80, 0x5F1528B43AB810C2, 0x09F8169BA49A54B3, 0xC094410E731D5BF1, 0x6D4E3D514F59D312, 0xA4226AC498DEDC50, - 0x78F572DAA8D1420E, 0xB199254F7F564D4C, 0x1C4359104312C5AF, 0xD52F0E859495CAED, 0x83C230AA0AB78E9C, 0x4AAE673FDD3081DE, 0xE7741B60E174093D, 0x2E184CF536F3067F, - 0x056ED3E2F9E22447, 0xCC0284772E652B05, 0x61D8F8281221A3E6, 0xA8B4AFBDC5A6ACA4, 0xFE5991925B84E8D5, 0x3735C6078C03E797, 0x9AEFBA58B0476F74, 0x5383EDCD67C06036, - 0xB32E4CBE03A75F6F, 0x7A421B2BD420502D, 0xD7986774E864D8CE, 0x1EF430E13FE3D78C, 0x48190ECEA1C193FD, 0x8175595B76469CBF, 0x2CAF25044A02145C, 0xE5C372919D851B1E, - 0xCEB5ED8652943926, 0x07D9BA1385133664, 0xAA03C64CB957BE87, 0x636F91D96ED0B1C5, 0x3582AFF6F0F2F5B4, 0xFCEEF8632775FAF6, 0x5134843C1B317215, 0x9858D3A9CCB67D57, - 0x448FCBB7FCB9E309, 0x8DE39C222B3EEC4B, 0x2039E07D177A64A8, 0xE955B7E8C0FD6BEA, 0xBFB889C75EDF2F9B, 0x76D4DE52895820D9, 0xDB0EA20DB51CA83A, 0x1262F598629BA778, - 0x39146A8FAD8A8540, 0xF0783D1A7A0D8A02, 0x5DA24145464902E1, 0x94CE16D091CE0DA3, 0xC22328FF0FEC49D2, 0x0B4F7F6AD86B4690, 0xA6950335E42FCE73, 0x6FF954A033A8C131, - 0xC8FE8F3AFC28015C, 0x0192D8AF2BAF0E1E, 0xAC48A4F017EB86FD, 0x6524F365C06C89BF, 0x33C9CD4A5E4ECDCE, 0xFAA59ADF89C9C28C, 0x577FE680B58D4A6F, 0x9E13B115620A452D, - 0xB5652E02AD1B6715, 0x7C0979977A9C6857, 0xD1D305C846D8E0B4, 0x18BF525D915FEFF6, 0x4E526C720F7DAB87, 0x873E3BE7D8FAA4C5, 0x2AE447B8E4BE2C26, 0xE388102D33392364, - 0x3F5F08330336BD3A, 0xF6335FA6D4B1B278, 0x5BE923F9E8F53A9B, 0x9285746C3F7235D9, 0xC4684A43A15071A8, 0x0D041DD676D77EEA, 0xA0DE61894A93F609, 0x69B2361C9D14F94B, - 0x42C4A90B5205DB73, 0x8BA8FE9E8582D431, 0x267282C1B9C65CD2, 0xEF1ED5546E415390, 0xB9F3EB7BF06317E1, 0x709FBCEE27E418A3, 0xDD45C0B11BA09040, 0x14299724CC279F02, - 0x47AA7AE9ABE7FF34, 0x8EC62D7C7C60F076, 0x231C512340247895, 0xEA7006B697A377D7, 0xBC9D3899098133A6, 0x75F16F0CDE063CE4, 0xD82B1353E242B407, 0x114744C635C5BB45, - 0x3A31DBD1FAD4997D, 0xF35D8C442D53963F, 0x5E87F01B11171EDC, 0x97EBA78EC690119E, 0xC10699A158B255EF, 0x086ACE348F355AAD, 0xA5B0B26BB371D24E, 0x6CDCE5FE64F6DD0C, - 0xB00BFDE054F94352, 0x7967AA75837E4C10, 0xD4BDD62ABF3AC4F3, 0x1DD181BF68BDCBB1, 0x4B3CBF90F69F8FC0, 0x8250E80521188082, 0x2F8A945A1D5C0861, 0xE6E6C3CFCADB0723, - 0xCD905CD805CA251B, 0x04FC0B4DD24D2A59, 0xA9267712EE09A2BA, 0x604A2087398EADF8, 0x36A71EA8A7ACE989, 0xFFCB493D702BE6CB, 0x521135624C6F6E28, 0x9B7D62F79BE8616A, - 0x3C7AB96D5468A107, 0xF516EEF883EFAE45, 0x58CC92A7BFAB26A6, 0x91A0C532682C29E4, 0xC74DFB1DF60E6D95, 0x0E21AC88218962D7, 0xA3FBD0D71DCDEA34, 0x6A978742CA4AE576, - 0x41E11855055BC74E, 0x888D4FC0D2DCC80C, 0x2557339FEE9840EF, 0xEC3B640A391F4FAD, 0xBAD65A25A73D0BDC, 0x73BA0DB070BA049E, 0xDE6071EF4CFE8C7D, 0x170C267A9B79833F, - 0xCBDB3E64AB761D61, 0x02B769F17CF11223, 0xAF6D15AE40B59AC0, 0x6601423B97329582, 0x30EC7C140910D1F3, 0xF9802B81DE97DEB1, 0x545A57DEE2D35652, 0x9D36004B35545910, - 0xB6409F5CFA457B28, 0x7F2CC8C92DC2746A, 0xD2F6B4961186FC89, 0x1B9AE303C601F3CB, 0x4D77DD2C5823B7BA, 0x841B8AB98FA4B8F8, 0x29C1F6E6B3E0301B, 0xE0ADA17364673F59 - }; - - return (crc >> 8) ^ table[(crc ^ value) & 0xFF]; - } - }; - - //*************************************************************************** - /// CRC64 Poly 0x42F0E1EBA9EA3693 policy. - /// Calculates CRC64 using polynomial 0x42F0E1EBA9EA3693 - //*************************************************************************** - template - struct crc64_policy_poly_0x42f0e1eba9ea3693 : public crc64_table_poly_0x42f0e1eba9ea3693 - { - typedef uint64_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint64_t initial() const - { - return INITIAL; - } - - //************************************************************************* - uint64_t final(uint64_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //*************************************************************************** - /// CRC64 Poly 0x42F0E1EBA9EA3693 reflected policy specialisation. - //*************************************************************************** - template - struct crc64_policy_poly_0x42f0e1eba9ea3693 : public crc64_table_poly_0x42f0e1eba9ea3693_reflected - { - typedef uint64_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint64_t initial() const - { - return INITIAL; - } - - //************************************************************************* - uint64_t final(uint64_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //************************************************************************* - /// CRC64 Poly 0x42F0E1EBA9EA3693 - //************************************************************************* - template - class crc64_poly_0x42f0e1eba9ea3693 : public etl::frame_check_sequence > - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc64_poly_0x42f0e1eba9ea3693() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc64_poly_0x42f0e1eba9ea3693(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; -} - -#endif diff --git a/include/etl/private/crc8_poly_0x07.h b/include/etl/private/crc8_poly_0x07.h deleted file mode 100644 index 6e28e534..00000000 --- a/include/etl/private/crc8_poly_0x07.h +++ /dev/null @@ -1,191 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2019 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef ETL_CRC8_POLY_0x07_INCLUDED -#define ETL_CRC8_POLY_0x07_INCLUDED - -#include - -#include "../platform.h" -#include "../frame_check_sequence.h" -#include "../binary.h" -#include "../iterator.h" - -#if defined(ETL_COMPILER_KEIL) -#pragma diag_suppress 1300 -#endif - -///\defgroup crc8_poly_0x07 8 bit CRC Poly 0x07 calculation -///\ingroup crc - -namespace etl -{ - //*************************************************************************** - /// - //*************************************************************************** - class crc8_table_poly_0x07 - { - public: - - //************************************************************************* - uint8_t add(uint8_t crc, uint8_t value) const - { - static const uint8_t table[256] = - { - 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, - 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, - 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, - 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD, - 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, - 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A, - 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A, - 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, - 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4, - 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4, - 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, - 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34, - 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63, - 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, - 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83, - 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3 - }; - - return table[crc ^ value]; - } - }; - - //*************************************************************************** - /// - //*************************************************************************** - class crc8_table_poly_0x07_reflected - { - public: - - //************************************************************************* - uint8_t add(uint8_t crc, uint8_t value) const - { - static const uint8_t table[256] = - { - 0x00, 0x91, 0xe3, 0x72, 0x07, 0x96, 0xe4, 0x75, 0x0e, 0x9f, 0xed, 0x7c, 0x09, 0x98, 0xea, 0x7b, - 0x1c, 0x8d, 0xff, 0x6e, 0x1b, 0x8a, 0xf8, 0x69, 0x12, 0x83, 0xf1, 0x60, 0x15, 0x84, 0xf6, 0x67, - 0x38, 0xa9, 0xdb, 0x4a, 0x3f, 0xae, 0xdc, 0x4d, 0x36, 0xa7, 0xd5, 0x44, 0x31, 0xa0, 0xd2, 0x43, - 0x24, 0xb5, 0xc7, 0x56, 0x23, 0xb2, 0xc0, 0x51, 0x2a, 0xbb, 0xc9, 0x58, 0x2d, 0xbc, 0xce, 0x5f, - 0x70, 0xe1, 0x93, 0x02, 0x77, 0xe6, 0x94, 0x05, 0x7e, 0xef, 0x9d, 0x0c, 0x79, 0xe8, 0x9a, 0x0b, - 0x6c, 0xfd, 0x8f, 0x1e, 0x6b, 0xfa, 0x88, 0x19, 0x62, 0xf3, 0x81, 0x10, 0x65, 0xf4, 0x86, 0x17, - 0x48, 0xd9, 0xab, 0x3a, 0x4f, 0xde, 0xac, 0x3d, 0x46, 0xd7, 0xa5, 0x34, 0x41, 0xd0, 0xa2, 0x33, - 0x54, 0xc5, 0xb7, 0x26, 0x53, 0xc2, 0xb0, 0x21, 0x5a, 0xcb, 0xb9, 0x28, 0x5d, 0xcc, 0xbe, 0x2f, - 0xe0, 0x71, 0x03, 0x92, 0xe7, 0x76, 0x04, 0x95, 0xee, 0x7f, 0x0d, 0x9c, 0xe9, 0x78, 0x0a, 0x9b, - 0xfc, 0x6d, 0x1f, 0x8e, 0xfb, 0x6a, 0x18, 0x89, 0xf2, 0x63, 0x11, 0x80, 0xf5, 0x64, 0x16, 0x87, - 0xd8, 0x49, 0x3b, 0xaa, 0xdf, 0x4e, 0x3c, 0xad, 0xd6, 0x47, 0x35, 0xa4, 0xd1, 0x40, 0x32, 0xa3, - 0xc4, 0x55, 0x27, 0xb6, 0xc3, 0x52, 0x20, 0xb1, 0xca, 0x5b, 0x29, 0xb8, 0xcd, 0x5c, 0x2e, 0xbf, - 0x90, 0x01, 0x73, 0xe2, 0x97, 0x06, 0x74, 0xe5, 0x9e, 0x0f, 0x7d, 0xec, 0x99, 0x08, 0x7a, 0xeb, - 0x8c, 0x1d, 0x6f, 0xfe, 0x8b, 0x1a, 0x68, 0xf9, 0x82, 0x13, 0x61, 0xf0, 0x85, 0x14, 0x66, 0xf7, - 0xa8, 0x39, 0x4b, 0xda, 0xaf, 0x3e, 0x4c, 0xdd, 0xa6, 0x37, 0x45, 0xd4, 0xa1, 0x30, 0x42, 0xd3, - 0xb4, 0x25, 0x57, 0xc6, 0xb3, 0x22, 0x50, 0xc1, 0xba, 0x2b, 0x59, 0xc8, 0xbd, 0x2c, 0x5e, 0xcf - }; - - return table[crc ^ value]; - } - }; - - //*************************************************************************** - /// CRC8 Poly 0x07 policy. - /// Calculates CRC8 using polynomial 0x07 - //*************************************************************************** - template - struct crc8_policy_poly_0x07 : public crc8_table_poly_0x07 - { - typedef uint8_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint8_t initial() const - { - return INITIAL; - } - - //************************************************************************* - uint8_t final(uint8_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //*************************************************************************** - /// CRC8 Poly 0x07 reflected policy specialisation. - //*************************************************************************** - template - struct crc8_policy_poly_0x07 : public crc8_table_poly_0x07_reflected - { - typedef uint8_t value_type; - - //************************************************************************* - ETL_CONSTEXPR uint8_t initial() const - { - return INITIAL; - } - - //************************************************************************* - uint8_t final(uint8_t crc) const - { - return crc ^ XOR_OUT; - } - }; - - //************************************************************************* - /// CRC8 Poly 0x07 - //************************************************************************* - template - class crc8_poly_0x07 : public etl::frame_check_sequence > - { - public: - - //************************************************************************* - /// Default constructor. - //************************************************************************* - crc8_poly_0x07() - { - this->reset(); - } - - //************************************************************************* - /// Constructor from range. - /// \param begin Start of the range. - /// \param end End of the range. - //************************************************************************* - template - crc8_poly_0x07(TIterator begin, const TIterator end) - { - this->reset(); - this->add(begin, end); - } - }; -} - -#endif diff --git a/include/etl/experimental/crc_implementation_2.h b/include/etl/private/crc_implementation.h similarity index 78% rename from include/etl/experimental/crc_implementation_2.h rename to include/etl/private/crc_implementation.h index b6945f0c..8cdd1722 100644 --- a/include/etl/experimental/crc_implementation_2.h +++ b/include/etl/private/crc_implementation.h @@ -8,43 +8,16 @@ #include "stdint.h" +#include "crc_parameters.h" + +#if defined(ETL_COMPILER_KEIL) +#pragma diag_suppress 1300 +#endif + namespace etl { namespace private_crc { - //***************************************************************************** - /// CRC Traits - //***************************************************************************** - template - struct crc_traits; - - //********************************* - // Traits for table size of 4. - template <> - struct crc_traits<4U> - { - static ETL_CONSTANT uint8_t Chunk_Mask = 0x03U; - static ETL_CONSTANT size_t Chunk_Bits = 2U; - }; - - //********************************* - // Traits for table size of 16. - template <> - struct crc_traits<16U> - { - static ETL_CONSTANT uint8_t Chunk_Mask = 0x0FU; - static ETL_CONSTANT size_t Chunk_Bits = 4U; - }; - - //********************************* - // Traits for table size of 256. - template <> - struct crc_traits<256U> - { - static ETL_CONSTANT uint8_t Chunk_Mask = 0xFFU; - static ETL_CONSTANT size_t Chunk_Bits = 8U; - }; - //***************************************************************************** /// CRC Entry //***************************************************************************** @@ -53,7 +26,7 @@ namespace etl { private: - typename typedef TCrcParameters::accumulator_type accumulator_type; + typedef typename TCrcParameters::accumulator_type accumulator_type; static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; static ETL_CONSTANT accumulator_type Polynomial = TCrcParameters::Polynomial; @@ -136,59 +109,59 @@ namespace etl crc_entry::value>::value; }; - //************************************************************************* - // Accumulator_Bits > Chunk_Bits and not reflected - template - typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && !Reflect, TAccumulator>::type - crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + ////************************************************************************* + //// Accumulator_Bits > Chunk_Bits and not reflected + //template + //typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && !Reflect, TAccumulator>::type + // crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + //{ + // size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; - crc <<= Chunk_Bits; - crc ^= table[index]; + // crc <<= Chunk_Bits; + // crc ^= table[index]; - return crc; - } + // return crc; + //} - //************************************************************************* - // Accumulator_Bits > Chunk_Bits and reflected - template - typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && Reflect, TAccumulator>::type - crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - size_t index = (crc & Chunk_Mask) ^ value; + ////************************************************************************* + //// Accumulator_Bits > Chunk_Bits and reflected + //template + //typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && Reflect, TAccumulator>::type + // crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + //{ + // size_t index = size_t((crc & Chunk_Mask) ^ value); - crc >>= Chunk_Bits; - crc ^= table[index]; + // crc >>= Chunk_Bits; + // crc ^= table[index]; - return crc; - } + // return crc; + //} - //************************************************************************* - // Accumulator_Bits == Chunk_Bits and not reflected - template - typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && !Reflect, TAccumulator>::type - crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + ////************************************************************************* + //// Accumulator_Bits == Chunk_Bits and not reflected + //template + //typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && !Reflect, TAccumulator>::type + // crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + //{ + // size_t index = size_t((crc >> (Accumulator_Bits - Chunk_Bits)) ^ value); - crc = table[index]; + // crc = table[index]; - return crc; - } + // return crc; + //} - //************************************************************************* - // Accumulator_Bits == Chunk_Bits and reflected - template - typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && Reflect, TAccumulator>::type - crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - { - size_t index = (crc & Chunk_Mask) ^ value; + ////************************************************************************* + //// Accumulator_Bits == Chunk_Bits and reflected + //template + //typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && Reflect, TAccumulator>::type + // crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + //{ + // size_t index = size_t((crc & Chunk_Mask) ^ value); - crc = table[index]; + // crc = table[index]; - return crc; - } + // return crc; + //} //***************************************************************************** // CRC Policies. @@ -205,8 +178,8 @@ namespace etl typedef accumulator_type value_type; static ETL_CONSTANT size_t Table_Size = 256U; - static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; - static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; + static ETL_CONSTANT uint8_t Chunk_Mask = Table_Size - 1U; + static ETL_CONSTANT size_t Chunk_Bits = 8U; static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; //************************************************************************* @@ -215,6 +188,54 @@ namespace etl return TCrcParameters::Initial; } + //************************************************************************* + static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) + { + //// Extract the most significant nibble of the crc and xor with the value nibble. + //size_t index = size_t((crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value); + + //crc <<= Chunk_Bits; + //crc ^= table[index]; + + value &= Chunk_Mask; + + if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) + { + uint8_t index = (crc & Chunk_Mask) ^ value; + + // special case for when chunk size is same as accumulator size. + if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) + { + crc >>= Chunk_Bits; + crc ^= table[index]; + } + else + { + crc = table[index]; + } + + return crc; + } + else + { + // Extract the most significant nibble of the crc and xor with the value nibble + uint8_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + + // special case for when chunk size is same as accumulator size. + if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) + { + crc <<= Chunk_Bits; + crc ^= table[index]; + } + else + { + crc = table[index]; + } + + return crc; + } + } + //************************************************************************* accumulator_type add(accumulator_type crc, uint8_t value) const { @@ -478,7 +499,8 @@ namespace etl crc_table_entry::value }; - crc = crc_update_chunk(crc, value, table); + crc = update_chunk(crc, value, table); + //crc = crc_update_chunk(crc, value, table); return crc; } @@ -499,8 +521,8 @@ namespace etl typedef accumulator_type value_type; static ETL_CONSTANT size_t Table_Size = 16U; - static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; - static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; + static ETL_CONSTANT uint8_t Chunk_Mask = Table_Size - 1U; + static ETL_CONSTANT size_t Chunk_Bits = 4U; static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; typedef accumulator_type value_type; @@ -514,13 +536,49 @@ namespace etl //************************************************************************* static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) { - // Extract the most significant nibble of the crc and xor with the value nibble. - size_t index = (crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value; + //// Extract the most significant nibble of the crc and xor with the value nibble. + //size_t index = size_t((crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value); - crc <<= Chunk_Bits; - crc ^= table[index]; + //crc <<= Chunk_Bits; + //crc ^= table[index]; - return crc; + value &= Chunk_Mask; + + if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) + { + uint8_t index = (crc & Chunk_Mask) ^ value; + + // special case for when chunk size is same as accumulator size. + if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) + { + crc >>= Chunk_Bits; + crc ^= table[index]; + } + else + { + crc = table[index]; + } + + return crc; + } + else + { + // Extract the most significant nibble of the crc and xor with the value nibble + uint8_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + + // special case for when chunk size is same as accumulator size. + if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) + { + crc <<= Chunk_Bits; + crc ^= table[index]; + } + else + { + crc = table[index]; + } + + return crc; + } } //************************************************************************* @@ -546,8 +604,16 @@ namespace etl crc_table_entry::value }; - crc = update_chunk(crc, (value >> Chunk_Bits) & Chunk_Mask, table); - crc = update_chunk(crc, value & Chunk_Mask, table); + if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) + { + crc = update_chunk(crc, value & Chunk_Mask, table); + crc = update_chunk(crc, value >> Chunk_Bits, table); + } + else + { + crc = update_chunk(crc, value >> Chunk_Bits, table); + crc = update_chunk(crc, value & Chunk_Mask, table); + } return crc; } @@ -568,8 +634,8 @@ namespace etl typedef accumulator_type value_type; static ETL_CONSTANT size_t Table_Size = 4U; - static ETL_CONSTANT uint8_t Chunk_Mask = crc_traits::Chunk_Mask; - static ETL_CONSTANT uint8_t Chunk_Bits = crc_traits::Chunk_Bits; + static ETL_CONSTANT uint8_t Chunk_Mask = Table_Size - 1U; + static ETL_CONSTANT size_t Chunk_Bits = 2U; static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; //************************************************************************* @@ -581,13 +647,43 @@ namespace etl //************************************************************************* static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) { - // Extract the most significant nibble of the crc and xor with the value nibble. - size_t index = (crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value; + value &= Chunk_Mask; - crc <<= Chunk_Bits; - crc ^= table[index]; + if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) + { + uint8_t index = (crc & Chunk_Mask) ^ value; - return crc; + // special case for when chunk size is same as accumulator size. + if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) + { + crc >>= Chunk_Bits; + crc ^= table[index]; + } + else + { + crc = table[index]; + } + + return crc; + } + else + { + // Extract the most significant nibble of the crc and xor with the value nibble + uint8_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + + // special case for when chunk size is same as accumulator size. + if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) + { + crc <<= Chunk_Bits; + crc ^= table[index]; + } + else + { + crc = table[index]; + } + + return crc; + } } //************************************************************************* @@ -600,11 +696,21 @@ namespace etl crc_table_entry::value, crc_table_entry::value }; - - crc = update_chunk(crc, (value >> (Chunk_Bits * 3U)) & Chunk_Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Bits * 2U)) & Chunk_Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Bits * 1U)) & Chunk_Mask, table); - crc = update_chunk(crc, value & Chunk_Mask, table); + + if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) + { + crc = update_chunk(crc, value & Chunk_Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Bits * 1U)) & Chunk_Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Bits * 2U)) & Chunk_Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Bits * 3U)) & Chunk_Mask, table); + } + else + { + crc = update_chunk(crc, (value >> (Chunk_Bits * 3U)) & Chunk_Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Bits * 2U)) & Chunk_Mask, table); + crc = update_chunk(crc, (value >> (Chunk_Bits * 1U)) & Chunk_Mask, table); + crc = update_chunk(crc, value & Chunk_Mask, table); + } return crc; } diff --git a/include/etl/experimental/crc_parameters.h b/include/etl/private/crc_parameters.h similarity index 53% rename from include/etl/experimental/crc_parameters.h rename to include/etl/private/crc_parameters.h index ffa4e8ca..f1c4796c 100644 --- a/include/etl/experimental/crc_parameters.h +++ b/include/etl/private/crc_parameters.h @@ -21,6 +21,14 @@ namespace etl // 8 bit. typedef crc_parameters crc8_ccitt_parameters; typedef crc_parameters crc8_rohc_parameters; + typedef crc_parameters crc8_cdma2000; + typedef crc_parameters crc8_darc; + typedef crc_parameters crc8_dvbs2; + typedef crc_parameters crc8_ebu; + typedef crc_parameters crc8_icode; + typedef crc_parameters crc8_itu; + typedef crc_parameters crc8_maxim; + typedef crc_parameters crc8_wcdma; // 16 bit. typedef crc_parameters crc16_parameters; @@ -32,6 +40,20 @@ namespace etl typedef crc_parameters crc16_usb_parameters; typedef crc_parameters crc16_x25_parameters; typedef crc_parameters crc16_xmodem_parameters; + typedef crc_parameters crc16_buypass; + typedef crc_parameters crc16_cdma2000; + typedef crc_parameters crc16_dds110; + typedef crc_parameters crc16_dectr; + typedef crc_parameters crc16_dectx; + typedef crc_parameters crc16_dnp; + typedef crc_parameters crc16_en13757; + typedef crc_parameters crc16_maxim; + typedef crc_parameters crc16_mcrf4xx; + typedef crc_parameters crc16_riello; + typedef crc_parameters crc16_t10dif; + typedef crc_parameters crc16_teledisk; + typedef crc_parameters crc16_tms37157; + typedef crc_parameters crc16_a; // 32 bit. typedef crc_parameters crc32_parameters; @@ -39,6 +61,10 @@ namespace etl typedef crc_parameters crc32_bzip2_parameters; typedef crc_parameters crc32_mpeg2_parameters; typedef crc_parameters crc32_posix_parameters; + typedef crc_parameters crc32_d; + typedef crc_parameters crc32_q; + typedef crc_parameters crc32_jamcrc; + typedef crc_parameters crc32_xfer; // 64 bit. typedef crc_parameters crc64_ecma_parameters; diff --git a/test/etl_profile.h b/test/etl_profile.h index d5d74d81..1c24412d 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -93,6 +93,7 @@ SOFTWARE. //#define ETL_LARGEST_TYPE_FORCE_CPP03 //#define ETL_TYPE_SELECT_FORCE_CPP03 //#define ETL_UNINITIALIZED_BUFFER_FORCE_CPP03 +//#define ETL_CRC_FORCE_CPP03 #if defined(ETL_NO_STL) #define ETL_TIMER_SEMAPHORE_TYPE uint32_t diff --git a/test/test_crc_table16.cpp b/test/test_crc_table16.cpp index 09fd98f2..eae752b5 100644 --- a/test/test_crc_table16.cpp +++ b/test/test_crc_table16.cpp @@ -1,1259 +1,1257 @@ -///****************************************************************************** -//The MIT License(MIT) -// -//Embedded Template Library. -//https://github.com/ETLCPP/etl -//https://www.etlcpp.com -// -//Copyright(c) 2014 jwellbelove -// -//Permission is hereby granted, free of charge, to any person obtaining a copy -//of this software and associated documentation files(the "Software"), to deal -//in the Software without restriction, including without limitation the rights -//to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -//copies of the Software, and to permit persons to whom the Software is -//furnished to do so, subject to the following conditions : -// -//The above copyright notice and this permission notice shall be included in all -//copies or substantial portions of the Software. -// -//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -//SOFTWARE. -//******************************************************************************/ -// -//#include "unit_test_framework.h" -// -//#include -//#include -//#include -//#include -// -//#include "etl/experimental/crc8_ccitt.h" -//#include "etl/experimental/crc8_rohc.h" -////#include "etl/experimental/crc16.h" -////#include "etl/crc16.h" -////#include "etl/crc16_ccitt.h" -////#include "etl/crc16_aug_ccitt.h" -////#include "etl/crc16_kermit.h" -////#include "etl/crc16_modbus.h" -////#include "etl/crc16_usb.h" -////#include "etl/crc16_xmodem.h" -////#include "etl/crc16_genibus.h" -////#include "etl/crc16_x25.h" -////#include "etl/crc32.h" -////#include "etl/crc32_c.h" -////#include "etl/crc32_bzip2.h" -////#include "etl/crc32_mpeg2.h" -////#include "etl/crc32_posix.h" -////#include "etl/crc64_ecma.h" -// -////***************************************************************************** -//// The results for these tests were created from https://crccalc.com/ -////***************************************************************************** -// -//namespace -//{ -// SUITE(test_crc_experimental) -// { -// ////************************************************************************* -// //TEST(test_crc8_ccitt_constructor) -// //{ -// // std::string data("123456789"); -// -// // uint8_t crc = etl::crc::crc8_ccitt_t16(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xF4, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_ccitt_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_ccitt_t16 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint8_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xF4, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_ccitt_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_ccitt_t16 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint8_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xF4, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_ccitt_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_ccitt_t16 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint8_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xF4, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_ccitt_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); -// // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(int(crc1), int(crc2)); -// -// // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(int(crc1), int(crc3)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_constructor) -// //{ -// // std::string data("123456789"); -// -// // uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xD0, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_rohc crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint8_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xD0, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_rohc crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint8_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xD0, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_rohc crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint8_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xD0, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); -// // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(int(crc1), int(crc2)); -// -// // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(int(crc1), int(crc3)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc::crc16(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xBB3D, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc16 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xBB3D, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc16 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xBB3D, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc16 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xBB3D, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x29B1, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_ccitt crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x29B1, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_ccitt crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x29B1, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_ccitt crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x29B1, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x2189, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_kermit crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x2189, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_kermit crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x2189, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_kermit crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x2189, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x4B37, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_modbus crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x4B37, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_modbus crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x4B37, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_modbus crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x4B37, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_usb(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xB4C8, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_usb crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xB4C8, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_usb crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xB4C8, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_usb crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xB4C8, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x31C3, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_xmodem crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x31C3, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_xmodem crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x31C3, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_xmodem crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x31C3, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xE5CC, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_aug_ccitt crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xE5CC, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_aug_ccitt crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xE5CC, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_aug_ccitt crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xE5CC, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xD64E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_genibus crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xD64E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_genibus crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xD64E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_genibus crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xD64E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_x25(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x906E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_x25 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x906E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_x25 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x906E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_x25 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x906E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xCBF43926, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0xCBF43926, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xCBF43926, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xCBF43926, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32_c(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xE3069283, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_c crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0xE3069283, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_c crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xE3069283, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_c crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xE3069283, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xFC891918, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_bzip2 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0xFC891918, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_bzip2 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xFC891918, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_bzip2 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xFC891918, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x765E7680, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_posix crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0x765E7680, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_posix crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x765E7680, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_posix crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x765E7680, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x0376E6E7, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_mpeg2 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0x0376E6E7, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_mpeg2 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x0376E6E7, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_mpeg2 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x0376E6E7, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma) -// //{ -// // std::string data("123456789"); -// -// // uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc64_ecma crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint64_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc64_ecma crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint64_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc64_ecma crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint64_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); -// // uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// }; -//} -// +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_ccitt.h" +#include "etl/crc8_rohc.h" +#include "etl/crc16.h" +#include "etl/crc16_aug_ccitt.h" +#include "etl/crc16_ccitt.h" +#include "etl/crc16_kermit.h" +#include "etl/crc16_modbus.h" +#include "etl/crc16_usb.h" +#include "etl/crc16_genibus.h" +#include "etl/crc16_x25.h" +#include "etl/crc16_xmodem.h" +#include "etl/crc32.h" +#include "etl/crc32_c.h" +#include "etl/crc32_bzip2.h" +#include "etl/crc32_mpeg2.h" +#include "etl/crc32_posix.h" +#include "etl/crc64_ecma.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_t16_experimental) + { + //************************************************************************* + TEST(test_crc8_ccitt_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_ccitt_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc8_ccitt_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc8_ccitt_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_ccitt_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_ccitt_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_ccitt_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_ccitt_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + TEST(test_crc8_rohc_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_rohc_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_values) + { + std::string data("123456789"); + + etl::crc8_rohc_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_range) + { + std::string data("123456789"); + + etl::crc8_rohc_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_rohc_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_rohc_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_rohc_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_rohc_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + TEST(test_crc16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_values) + { + std::string data("123456789"); + + etl::crc16_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range) + { + std::string data("123456789"); + + etl::crc16_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_ccitt) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_ccitt_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc16_ccitt_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc16_ccitt_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_ccitt_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_ccitt_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_ccitt_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_ccitt_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_kermit) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_kermit_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_values) + { + std::string data("123456789"); + + etl::crc16_kermit_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range) + { + std::string data("123456789"); + + etl::crc16_kermit_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_kermit_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_kermit_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_kermit_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_kermit_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_modbus) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_modbus_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_values) + { + std::string data("123456789"); + + etl::crc16_modbus_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range) + { + std::string data("123456789"); + + etl::crc16_modbus_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_modbus_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_modbus_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_modbus_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_modbus_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_usb) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_usb_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_values) + { + std::string data("123456789"); + + etl::crc16_usb_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range) + { + std::string data("123456789"); + + etl::crc16_usb_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_usb_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_usb_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_usb_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_usb_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_xmodem) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_xmodem_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_values) + { + std::string data("123456789"); + + etl::crc16_xmodem_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range) + { + std::string data("123456789"); + + etl::crc16_xmodem_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_xmodem_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_xmodem_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_xmodem_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_xmodem_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_aug_ccitt_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_aug_ccitt_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_aug_ccitt_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_aug_ccitt_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_genibus) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_genibus_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_values) + { + std::string data("123456789"); + + etl::crc16_genibus_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range) + { + std::string data("123456789"); + + etl::crc16_genibus_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_genibus_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_genibus_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_genibus_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_genibus_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_x25) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_x25_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_values) + { + std::string data("123456789"); + + etl::crc16_x25_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range) + { + std::string data("123456789"); + + etl::crc16_x25_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_x25_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_x25_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_x25_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_x25_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_values) + { + std::string data("123456789"); + + etl::crc32_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range) + { + std::string data("123456789"); + + etl::crc32_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32_c) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_c_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xE3069283, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_values) + { + std::string data("123456789"); + + etl::crc32_c_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + + CHECK_EQUAL(0xE3069283, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_range) + { + std::string data("123456789"); + + etl::crc32_c_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_c_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_c_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_c_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_c_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32_bzip2) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_bzip2_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xFC891918, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_values) + { + std::string data("123456789"); + + etl::crc32_bzip2_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + + CHECK_EQUAL(0xFC891918, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_range) + { + std::string data("123456789"); + + etl::crc32_bzip2_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_bzip2_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_bzip2_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_bzip2_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_bzip2_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32_posix) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_posix_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x765E7680, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_values) + { + std::string data("123456789"); + + etl::crc32_posix_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x765E7680, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_range) + { + std::string data("123456789"); + + etl::crc32_posix_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_posix_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_posix_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_posix_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_posix_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32_mpeg2) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_mpeg2_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x0376E6E7, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_values) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + + CHECK_EQUAL(0x0376E6E7, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_range) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_mpeg2_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_mpeg2_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_mpeg2_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc64_ecma) + { + std::string data("123456789"); + + uint64_t crc = etl::crc64_ecma_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_values) + { + std::string data("123456789"); + + etl::crc64_ecma_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint64_t crc = crc_calculator; + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range) + { + std::string data("123456789"); + + etl::crc64_ecma_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc64_ecma_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint64_t crc1 = etl::crc64_ecma_t16(data1.begin(), data1.end()); + uint64_t crc2 = etl::crc64_ecma_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint64_t crc3 = etl::crc64_ecma_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc_table256.cpp b/test/test_crc_table256.cpp index 352805a4..20c04dcd 100644 --- a/test/test_crc_table256.cpp +++ b/test/test_crc_table256.cpp @@ -33,24 +33,23 @@ SOFTWARE. #include #include -#include "etl/experimental/crc8_ccitt.h" -#include "etl/experimental/crc8_rohc.h" -#include "etl/experimental/crc16.h" -#include "etl/experimental/crc16_aug_ccitt.h" -#include "etl/experimental/crc16_ccitt.h" -#include "etl/experimental/crc16_kermit.h" -#include "etl/experimental/crc16_modbus.h" -#include "etl/experimental/crc16_usb.h" -#include "etl/experimental/crc16_genibus.h" -#include "etl/experimental/crc16_x25.h" -#include "etl/experimental/crc16_xmodem.h" -#include "etl/experimental/crc32.h" -#include "etl/experimental/crc64_ecma.h" - -//#include "etl/crc32_c.h" -//#include "etl/crc32_bzip2.h" -//#include "etl/crc32_mpeg2.h" -//#include "etl/crc32_posix.h" +#include "etl/crc8_ccitt.h" +#include "etl/crc8_rohc.h" +#include "etl/crc16.h" +#include "etl/crc16_aug_ccitt.h" +#include "etl/crc16_ccitt.h" +#include "etl/crc16_kermit.h" +#include "etl/crc16_modbus.h" +#include "etl/crc16_usb.h" +#include "etl/crc16_genibus.h" +#include "etl/crc16_x25.h" +#include "etl/crc16_xmodem.h" +#include "etl/crc32.h" +#include "etl/crc32_c.h" +#include "etl/crc32_bzip2.h" +#include "etl/crc32_mpeg2.h" +#include "etl/crc32_posix.h" +#include "etl/crc64_ecma.h" //***************************************************************************** // The results for these tests were created from https://crccalc.com/ @@ -65,7 +64,7 @@ namespace { std::string data("123456789"); - uint8_t crc = etl::crc::crc8_ccitt(data.begin(), data.end()); + uint8_t crc = etl::crc8_ccitt(data.begin(), data.end()); CHECK_EQUAL(0xF4, int(crc)); } @@ -75,7 +74,7 @@ namespace { std::string data("123456789"); - etl::crc::crc8_ccitt crc_calculator; + etl::crc8_ccitt crc_calculator; for (size_t i = 0; i < data.size(); ++i) { @@ -92,7 +91,7 @@ namespace { std::string data("123456789"); - etl::crc::crc8_ccitt crc_calculator; + etl::crc8_ccitt crc_calculator; crc_calculator.add(data.begin(), data.end()); @@ -106,7 +105,7 @@ namespace { std::string data("123456789"); - etl::crc::crc8_ccitt crc_calculator; + etl::crc8_ccitt crc_calculator; std::copy(data.begin(), data.end(), crc_calculator.input()); @@ -122,11 +121,11 @@ namespace std::vector data2 = { 0x04030201, 0x08070605 }; std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - uint8_t crc1 = etl::crc::crc8_ccitt(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc::crc8_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + uint8_t crc1 = etl::crc8_ccitt(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); CHECK_EQUAL(int(crc1), int(crc2)); - uint8_t crc3 = etl::crc::crc8_ccitt(data3.rbegin(), data3.rend()); + uint8_t crc3 = etl::crc8_ccitt(data3.rbegin(), data3.rend()); CHECK_EQUAL(int(crc1), int(crc3)); } @@ -135,7 +134,7 @@ namespace { std::string data("123456789"); - uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); + uint8_t crc = etl::crc8_rohc(data.begin(), data.end()); CHECK_EQUAL(0xD0, int(crc)); } @@ -145,7 +144,7 @@ namespace { std::string data("123456789"); - etl::crc::crc8_rohc crc_calculator; + etl::crc8_rohc crc_calculator; for (size_t i = 0; i < data.size(); ++i) { @@ -162,7 +161,7 @@ namespace { std::string data("123456789"); - etl::crc::crc8_rohc crc_calculator; + etl::crc8_rohc crc_calculator; crc_calculator.add(data.begin(), data.end()); @@ -176,7 +175,7 @@ namespace { std::string data("123456789"); - etl::crc::crc8_rohc crc_calculator; + etl::crc8_rohc crc_calculator; std::copy(data.begin(), data.end(), crc_calculator.input()); @@ -192,11 +191,11 @@ namespace std::vector data2 = { 0x04030201, 0x08070605 }; std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - uint8_t crc1 = etl::crc::crc8_rohc(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc::crc8_rohc((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + uint8_t crc1 = etl::crc8_rohc(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_rohc((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); CHECK_EQUAL(int(crc1), int(crc2)); - uint8_t crc3 = etl::crc::crc8_rohc(data3.rbegin(), data3.rend()); + uint8_t crc3 = etl::crc8_rohc(data3.rbegin(), data3.rend()); CHECK_EQUAL(int(crc1), int(crc3)); } @@ -205,7 +204,7 @@ namespace { std::string data("123456789"); - uint16_t crc = etl::crc::crc16(data.begin(), data.end()); + uint16_t crc = etl::crc16(data.begin(), data.end()); CHECK_EQUAL(0xBB3D, crc); } @@ -215,7 +214,7 @@ namespace { std::string data("123456789"); - etl::crc::crc16 crc_calculator; + etl::crc16 crc_calculator; for (size_t i = 0; i < data.size(); ++i) { @@ -232,7 +231,7 @@ namespace { std::string data("123456789"); - etl::crc::crc16 crc_calculator; + etl::crc16 crc_calculator; crc_calculator.add(data.begin(), data.end()); @@ -246,7 +245,7 @@ namespace { std::string data("123456789"); - etl::crc::crc16 crc_calculator; + etl::crc16 crc_calculator; std::copy(data.begin(), data.end(), crc_calculator.input()); @@ -262,998 +261,998 @@ namespace std::vector data2 = { 0x04030201, 0x08070605 }; std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - uint16_t crc1 = etl::crc::crc16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); CHECK_EQUAL(crc1, crc2); - uint16_t crc3 = etl::crc::crc16(data3.rbegin(), data3.rend()); + uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); CHECK_EQUAL(crc1, crc3); } - ////************************************************************************* - //TEST(test_crc16_ccitt) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_ccitt) + { + std::string data("123456789"); - // uint16_t crc = etl::crc::crc16_ccitt(data.begin(), data.end()); + uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); - // CHECK_EQUAL(0x29B1, crc); - //} + CHECK_EQUAL(0x29B1, crc); + } - ////************************************************************************* - //TEST(test_crc16_ccitt_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_ccitt_add_values) + { + std::string data("123456789"); - // etl::crc::crc16_ccitt crc_calculator; + etl::crc16_ccitt crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint16_t crc = crc_calculator; + uint16_t crc = crc_calculator; - // CHECK_EQUAL(0x29B1, crc); - //} + CHECK_EQUAL(0x29B1, crc); + } - ////************************************************************************* - //TEST(test_crc16_ccitt_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_ccitt_add_range) + { + std::string data("123456789"); - // etl::crc::crc16_ccitt crc_calculator; + etl::crc16_ccitt crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x29B1, crc); - //} + CHECK_EQUAL(0x29B1, crc); + } - ////************************************************************************* - //TEST(test_crc16_ccitt_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_ccitt_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc16_ccitt crc_calculator; + etl::crc16_ccitt crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x29B1, crc); - //} + CHECK_EQUAL(0x29B1, crc); + } - ////************************************************************************* - //TEST(test_crc16_ccitt_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc16_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint16_t crc1 = etl::crc::crc16_ccitt(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint16_t crc3 = etl::crc::crc16_ccitt(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - ////************************************************************************* - //TEST(test_crc16_kermit) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_kermit) + { + std::string data("123456789"); - // uint16_t crc = etl::crc::crc16_kermit(data.begin(), data.end()); + uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); - // CHECK_EQUAL(0x2189, crc); - //} + CHECK_EQUAL(0x2189, crc); + } - ////************************************************************************* - //TEST(test_crc16_kermit_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_kermit_add_values) + { + std::string data("123456789"); - // etl::crc::crc16_kermit crc_calculator; + etl::crc16_kermit crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint16_t crc = crc_calculator; + uint16_t crc = crc_calculator; - // CHECK_EQUAL(0x2189, crc); - //} + CHECK_EQUAL(0x2189, crc); + } - ////************************************************************************* - //TEST(test_crc16_kermit_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_kermit_add_range) + { + std::string data("123456789"); - // etl::crc::crc16_kermit crc_calculator; + etl::crc16_kermit crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x2189, crc); - //} + CHECK_EQUAL(0x2189, crc); + } - ////************************************************************************* - //TEST(test_crc16_kermit_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_kermit_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc16_kermit crc_calculator; + etl::crc16_kermit crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x2189, crc); - //} + CHECK_EQUAL(0x2189, crc); + } - ////************************************************************************* - //TEST(test_crc16_kermit_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc16_kermit_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint16_t crc1 = etl::crc::crc16_kermit(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint16_t crc3 = etl::crc::crc16_kermit(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - ////************************************************************************* - //TEST(test_crc16_modbus) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_modbus) + { + std::string data("123456789"); - // uint16_t crc = etl::crc::crc16_modbus(data.begin(), data.end()); + uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); - // CHECK_EQUAL(0x4B37, crc); - //} + CHECK_EQUAL(0x4B37, crc); + } - ////************************************************************************* - //TEST(test_crc16_modbus_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_modbus_add_values) + { + std::string data("123456789"); - // etl::crc::crc16_modbus crc_calculator; + etl::crc16_modbus crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint16_t crc = crc_calculator; + uint16_t crc = crc_calculator; - // CHECK_EQUAL(0x4B37, crc); - //} + CHECK_EQUAL(0x4B37, crc); + } - ////************************************************************************* - //TEST(test_crc16_modbus_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_modbus_add_range) + { + std::string data("123456789"); - // etl::crc::crc16_modbus crc_calculator; + etl::crc16_modbus crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x4B37, crc); - //} + CHECK_EQUAL(0x4B37, crc); + } - ////************************************************************************* - //TEST(test_crc16_modbus_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_modbus_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc16_modbus crc_calculator; + etl::crc16_modbus crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x4B37, crc); - //} + CHECK_EQUAL(0x4B37, crc); + } - ////************************************************************************* - //TEST(test_crc16_modbus_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc16_modbus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint16_t crc1 = etl::crc::crc16_modbus(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint16_t crc3 = etl::crc::crc16_modbus(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - ////************************************************************************* - //TEST(test_crc16_usb) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_usb) + { + std::string data("123456789"); - // uint16_t crc = etl::crc::crc16_usb(data.begin(), data.end()); + uint16_t crc = etl::crc16_usb(data.begin(), data.end()); - // CHECK_EQUAL(0xB4C8, crc); - //} + CHECK_EQUAL(0xB4C8, crc); + } - ////************************************************************************* - //TEST(test_crc16_usb_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_usb_add_values) + { + std::string data("123456789"); - // etl::crc::crc16_usb crc_calculator; + etl::crc16_usb crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint16_t crc = crc_calculator; + uint16_t crc = crc_calculator; - // CHECK_EQUAL(0xB4C8, crc); - //} + CHECK_EQUAL(0xB4C8, crc); + } - ////************************************************************************* - //TEST(test_crc16_usb_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_usb_add_range) + { + std::string data("123456789"); - // etl::crc::crc16_usb crc_calculator; + etl::crc16_usb crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xB4C8, crc); - //} + CHECK_EQUAL(0xB4C8, crc); + } - ////************************************************************************* - //TEST(test_crc16_usb_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_usb_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc16_usb crc_calculator; + etl::crc16_usb crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xB4C8, crc); - //} + CHECK_EQUAL(0xB4C8, crc); + } - ////************************************************************************* - //TEST(test_crc16_usb_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc16_usb_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint16_t crc1 = etl::crc::crc16_usb(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint16_t crc3 = etl::crc::crc16_usb(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - ////************************************************************************* - //TEST(test_crc16_xmodem) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_xmodem) + { + std::string data("123456789"); - // uint16_t crc = etl::crc::crc16_xmodem(data.begin(), data.end()); + uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); - // CHECK_EQUAL(0x31C3, crc); - //} + CHECK_EQUAL(0x31C3, crc); + } - ////************************************************************************* - //TEST(test_crc16_xmodem_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_xmodem_add_values) + { + std::string data("123456789"); - // etl::crc::crc16_xmodem crc_calculator; + etl::crc16_xmodem crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint16_t crc = crc_calculator; + uint16_t crc = crc_calculator; - // CHECK_EQUAL(0x31C3, crc); - //} + CHECK_EQUAL(0x31C3, crc); + } - ////************************************************************************* - //TEST(test_crc16_xmodem_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_xmodem_add_range) + { + std::string data("123456789"); - // etl::crc::crc16_xmodem crc_calculator; + etl::crc16_xmodem crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x31C3, crc); - //} + CHECK_EQUAL(0x31C3, crc); + } - ////************************************************************************* - //TEST(test_crc16_xmodem_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_xmodem_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc16_xmodem crc_calculator; + etl::crc16_xmodem crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x31C3, crc); - //} + CHECK_EQUAL(0x31C3, crc); + } - ////************************************************************************* - //TEST(test_crc16_xmodem_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc16_xmodem_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint16_t crc1 = etl::crc::crc16_xmodem(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint16_t crc3 = etl::crc::crc16_xmodem(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - ////************************************************************************* - //TEST(test_crc16_aug_ccitt) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_aug_ccitt) + { + std::string data("123456789"); - // uint16_t crc = etl::crc::crc16_aug_ccitt(data.begin(), data.end()); + uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); - // CHECK_EQUAL(0xE5CC, crc); - //} + CHECK_EQUAL(0xE5CC, crc); + } - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_values) + { + std::string data("123456789"); - // etl::crc::crc16_aug_ccitt crc_calculator; + etl::crc16_aug_ccitt crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint16_t crc = crc_calculator; + uint16_t crc = crc_calculator; - // CHECK_EQUAL(0xE5CC, crc); - //} + CHECK_EQUAL(0xE5CC, crc); + } - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range) + { + std::string data("123456789"); - // etl::crc::crc16_aug_ccitt crc_calculator; + etl::crc16_aug_ccitt crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xE5CC, crc); - //} + CHECK_EQUAL(0xE5CC, crc); + } - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc16_aug_ccitt crc_calculator; + etl::crc16_aug_ccitt crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xE5CC, crc); - //} + CHECK_EQUAL(0xE5CC, crc); + } - ////************************************************************************* - //TEST(test_crc16_aug_ccitt_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint16_t crc1 = etl::crc::crc16_aug_ccitt(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint16_t crc3 = etl::crc::crc16_aug_ccitt(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - ////************************************************************************* - //TEST(test_crc16_genibus) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_genibus) + { + std::string data("123456789"); - // uint16_t crc = etl::crc::crc16_genibus(data.begin(), data.end()); + uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); - // CHECK_EQUAL(0xD64E, crc); - //} + CHECK_EQUAL(0xD64E, crc); + } - ////************************************************************************* - //TEST(test_crc16_genibus_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_genibus_add_values) + { + std::string data("123456789"); - // etl::crc::crc16_genibus crc_calculator; + etl::crc16_genibus crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint16_t crc = crc_calculator; + uint16_t crc = crc_calculator; - // CHECK_EQUAL(0xD64E, crc); - //} + CHECK_EQUAL(0xD64E, crc); + } - ////************************************************************************* - //TEST(test_crc16_genibus_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_genibus_add_range) + { + std::string data("123456789"); - // etl::crc::crc16_genibus crc_calculator; + etl::crc16_genibus crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xD64E, crc); - //} + CHECK_EQUAL(0xD64E, crc); + } - ////************************************************************************* - //TEST(test_crc16_genibus_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_genibus_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc16_genibus crc_calculator; + etl::crc16_genibus crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xD64E, crc); - //} + CHECK_EQUAL(0xD64E, crc); + } - ////************************************************************************* - //TEST(test_crc16_genibus_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc16_genibus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint16_t crc1 = etl::crc::crc16_genibus(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint16_t crc3 = etl::crc::crc16_genibus(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - ////************************************************************************* - //TEST(test_crc16_x25) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_x25) + { + std::string data("123456789"); - // uint16_t crc = etl::crc::crc16_x25(data.begin(), data.end()); + uint16_t crc = etl::crc16_x25(data.begin(), data.end()); - // CHECK_EQUAL(0x906E, crc); - //} + CHECK_EQUAL(0x906E, crc); + } - ////************************************************************************* - //TEST(test_crc16_x25_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_x25_add_values) + { + std::string data("123456789"); - // etl::crc::crc16_x25 crc_calculator; + etl::crc16_x25 crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint16_t crc = crc_calculator; + uint16_t crc = crc_calculator; - // CHECK_EQUAL(0x906E, crc); - //} + CHECK_EQUAL(0x906E, crc); + } - ////************************************************************************* - //TEST(test_crc16_x25_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_x25_add_range) + { + std::string data("123456789"); - // etl::crc::crc16_x25 crc_calculator; + etl::crc16_x25 crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x906E, crc); - //} + CHECK_EQUAL(0x906E, crc); + } - ////************************************************************************* - //TEST(test_crc16_x25_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc16_x25_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc16_x25 crc_calculator; + etl::crc16_x25 crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint16_t crc = crc_calculator.value(); + uint16_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x906E, crc); - //} + CHECK_EQUAL(0x906E, crc); + } - ////************************************************************************* - //TEST(test_crc16_x25_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc16_x25_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint16_t crc1 = etl::crc::crc16_x25(data1.begin(), data1.end()); - // uint16_t crc2 = etl::crc::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint16_t crc3 = etl::crc::crc16_x25(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - ////************************************************************************* - //TEST(test_crc32) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc32) + { + std::string data("123456789"); - // uint32_t crc = etl::crc::crc32(data.begin(), data.end()); + uint32_t crc = etl::crc32(data.begin(), data.end()); - // CHECK_EQUAL(0xCBF43926, crc); - //} + CHECK_EQUAL(0xCBF43926, crc); + } - ////************************************************************************* - //TEST(test_crc32_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_add_values) + { + std::string data("123456789"); - // etl::crc::crc32 crc_calculator; + etl::crc32 crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint32_t crc = crc_calculator; + uint32_t crc = crc_calculator; - // CHECK_EQUAL(0xCBF43926, crc); - //} + CHECK_EQUAL(0xCBF43926, crc); + } - ////************************************************************************* - //TEST(test_crc32_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_add_range) + { + std::string data("123456789"); - // etl::crc::crc32 crc_calculator; + etl::crc32 crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xCBF43926, crc); - //} + CHECK_EQUAL(0xCBF43926, crc); + } - ////************************************************************************* - //TEST(test_crc32_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc32 crc_calculator; + etl::crc32 crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - // CHECK_EQUAL(0xCBF43926, crc); - //} + CHECK_EQUAL(0xCBF43926, crc); + } - ////************************************************************************* - //TEST(test_crc32_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc32_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint32_t crc1 = etl::crc::crc32(data1.begin(), data1.end()); - // uint32_t crc2 = etl::crc::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint32_t crc3 = etl::crc::crc32(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - //////************************************************************************* - ////TEST(test_crc32_c) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_c) + { + std::string data("123456789"); - //// uint32_t crc = etl::crc32_c(data.begin(), data.end()); + uint32_t crc = etl::crc32_c(data.begin(), data.end()); - //// CHECK_EQUAL(0xE3069283, crc); - ////} + CHECK_EQUAL(0xE3069283, crc); + } - //////************************************************************************* - ////TEST(test_crc32_c_add_values) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_c_add_values) + { + std::string data("123456789"); - //// etl::crc32_c crc_calculator; + etl::crc32_c crc_calculator; - //// for (size_t i = 0; i < data.size(); ++i) - //// { - //// crc_calculator.add(data[i]); - //// } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - //// uint32_t crc = crc_calculator; + uint32_t crc = crc_calculator; - //// CHECK_EQUAL(0xE3069283, crc); - ////} + CHECK_EQUAL(0xE3069283, crc); + } - //////************************************************************************* - ////TEST(test_crc32_c_add_range) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_c_add_range) + { + std::string data("123456789"); - //// etl::crc32_c crc_calculator; + etl::crc32_c crc_calculator; - //// crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - //// uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - //// CHECK_EQUAL(0xE3069283, crc); - ////} + CHECK_EQUAL(0xE3069283, crc); + } - //////************************************************************************* - ////TEST(test_crc32_c_add_range_via_iterator) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_c_add_range_via_iterator) + { + std::string data("123456789"); - //// etl::crc32_c crc_calculator; + etl::crc32_c crc_calculator; - //// std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - //// uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - //// CHECK_EQUAL(0xE3069283, crc); - ////} + CHECK_EQUAL(0xE3069283, crc); + } - //////************************************************************************* - ////TEST(test_crc32_c_add_range_endian) - ////{ - //// std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - //// std::vector data2 = { 0x04030201, 0x08070605 }; - //// std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc32_c_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - //// uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); - //// uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - //// CHECK_EQUAL(crc1, crc2); + uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - //// uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); - //// CHECK_EQUAL(crc1, crc3); - ////} + uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - //////************************************************************************* - ////TEST(test_crc32_bzip2) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_bzip2) + { + std::string data("123456789"); - //// uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); + uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); - //// CHECK_EQUAL(0xFC891918, crc); - ////} + CHECK_EQUAL(0xFC891918, crc); + } - //////************************************************************************* - ////TEST(test_crc32_bzip2_add_values) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_bzip2_add_values) + { + std::string data("123456789"); - //// etl::crc32_bzip2 crc_calculator; + etl::crc32_bzip2 crc_calculator; - //// for (size_t i = 0; i < data.size(); ++i) - //// { - //// crc_calculator.add(data[i]); - //// } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - //// uint32_t crc = crc_calculator; + uint32_t crc = crc_calculator; - //// CHECK_EQUAL(0xFC891918, crc); - ////} + CHECK_EQUAL(0xFC891918, crc); + } - //////************************************************************************* - ////TEST(test_crc32_bzip2_add_range) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_bzip2_add_range) + { + std::string data("123456789"); - //// etl::crc32_bzip2 crc_calculator; + etl::crc32_bzip2 crc_calculator; - //// crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - //// uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - //// CHECK_EQUAL(0xFC891918, crc); - ////} + CHECK_EQUAL(0xFC891918, crc); + } - //////************************************************************************* - ////TEST(test_crc32_bzip2_add_range_via_iterator) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_bzip2_add_range_via_iterator) + { + std::string data("123456789"); - //// etl::crc32_bzip2 crc_calculator; + etl::crc32_bzip2 crc_calculator; - //// std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - //// uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - //// CHECK_EQUAL(0xFC891918, crc); - ////} + CHECK_EQUAL(0xFC891918, crc); + } - //////************************************************************************* - ////TEST(test_crc32_bzip2_add_range_endian) - ////{ - //// std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - //// std::vector data2 = { 0x04030201, 0x08070605 }; - //// std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc32_bzip2_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - //// uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); - //// uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - //// CHECK_EQUAL(crc1, crc2); + uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - //// uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); - //// CHECK_EQUAL(crc1, crc3); - ////} + uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - //////************************************************************************* - ////TEST(test_crc32_posix) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_posix) + { + std::string data("123456789"); - //// uint32_t crc = etl::crc32_posix(data.begin(), data.end()); + uint32_t crc = etl::crc32_posix(data.begin(), data.end()); - //// CHECK_EQUAL(0x765E7680, crc); - ////} + CHECK_EQUAL(0x765E7680, crc); + } - //////************************************************************************* - ////TEST(test_crc32_posix_add_values) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_posix_add_values) + { + std::string data("123456789"); - //// etl::crc32_posix crc_calculator; + etl::crc32_posix crc_calculator; - //// for (size_t i = 0; i < data.size(); ++i) - //// { - //// crc_calculator.add(data[i]); - //// } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - //// uint32_t crc = crc_calculator; + uint32_t crc = crc_calculator; - //// CHECK_EQUAL(0x765E7680, crc); - ////} + CHECK_EQUAL(0x765E7680, crc); + } - //////************************************************************************* - ////TEST(test_crc32_posix_add_range) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_posix_add_range) + { + std::string data("123456789"); - //// etl::crc32_posix crc_calculator; + etl::crc32_posix crc_calculator; - //// crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - //// uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - //// CHECK_EQUAL(0x765E7680, crc); - ////} + CHECK_EQUAL(0x765E7680, crc); + } - //////************************************************************************* - ////TEST(test_crc32_posix_add_range_via_iterator) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_posix_add_range_via_iterator) + { + std::string data("123456789"); - //// etl::crc32_posix crc_calculator; + etl::crc32_posix crc_calculator; - //// std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - //// uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - //// CHECK_EQUAL(0x765E7680, crc); - ////} + CHECK_EQUAL(0x765E7680, crc); + } - //////************************************************************************* - ////TEST(test_crc32_posix_add_range_endian) - ////{ - //// std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - //// std::vector data2 = { 0x04030201, 0x08070605 }; - //// std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc32_posix_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - //// uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); - //// uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - //// CHECK_EQUAL(crc1, crc2); + uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - //// uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); - //// CHECK_EQUAL(crc1, crc3); - ////} + uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - //////************************************************************************* - ////TEST(test_crc32_mpeg2) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_mpeg2) + { + std::string data("123456789"); - //// uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); + uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); - //// CHECK_EQUAL(0x0376E6E7, crc); - ////} + CHECK_EQUAL(0x0376E6E7, crc); + } - //////************************************************************************* - ////TEST(test_crc32_mpeg2_add_values) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_mpeg2_add_values) + { + std::string data("123456789"); - //// etl::crc32_mpeg2 crc_calculator; + etl::crc32_mpeg2 crc_calculator; - //// for (size_t i = 0; i < data.size(); ++i) - //// { - //// crc_calculator.add(data[i]); - //// } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - //// uint32_t crc = crc_calculator; + uint32_t crc = crc_calculator; - //// CHECK_EQUAL(0x0376E6E7, crc); - ////} + CHECK_EQUAL(0x0376E6E7, crc); + } - //////************************************************************************* - ////TEST(test_crc32_mpeg2_add_range) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_mpeg2_add_range) + { + std::string data("123456789"); - //// etl::crc32_mpeg2 crc_calculator; + etl::crc32_mpeg2 crc_calculator; - //// crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - //// uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - //// CHECK_EQUAL(0x0376E6E7, crc); - ////} + CHECK_EQUAL(0x0376E6E7, crc); + } - //////************************************************************************* - ////TEST(test_crc32_mpeg2_add_range_via_iterator) - ////{ - //// std::string data("123456789"); + //************************************************************************* + TEST(test_crc32_mpeg2_add_range_via_iterator) + { + std::string data("123456789"); - //// etl::crc32_mpeg2 crc_calculator; + etl::crc32_mpeg2 crc_calculator; - //// std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - //// uint32_t crc = crc_calculator.value(); + uint32_t crc = crc_calculator.value(); - //// CHECK_EQUAL(0x0376E6E7, crc); - ////} + CHECK_EQUAL(0x0376E6E7, crc); + } - //////************************************************************************* - ////TEST(test_crc32_mpeg2_add_range_endian) - ////{ - //// std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - //// std::vector data2 = { 0x04030201, 0x08070605 }; - //// std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc32_mpeg2_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - //// uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); - //// uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - //// CHECK_EQUAL(crc1, crc2); + uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - //// uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); - //// CHECK_EQUAL(crc1, crc3); - ////} + uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } - ////************************************************************************* - //TEST(test_crc64_ecma) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc64_ecma) + { + std::string data("123456789"); - // uint64_t crc = etl::crc::crc64_ecma(data.begin(), data.end()); + uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } - ////************************************************************************* - //TEST(test_crc64_ecma_add_values) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc64_ecma_add_values) + { + std::string data("123456789"); - // etl::crc::crc64_ecma crc_calculator; + etl::crc64_ecma crc_calculator; - // for (size_t i = 0; i < data.size(); ++i) - // { - // crc_calculator.add(data[i]); - // } + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } - // uint64_t crc = crc_calculator; + uint64_t crc = crc_calculator; - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } - ////************************************************************************* - //TEST(test_crc64_ecma_add_range) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc64_ecma_add_range) + { + std::string data("123456789"); - // etl::crc::crc64_ecma crc_calculator; + etl::crc64_ecma crc_calculator; - // crc_calculator.add(data.begin(), data.end()); + crc_calculator.add(data.begin(), data.end()); - // uint64_t crc = crc_calculator.value(); + uint64_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } - ////************************************************************************* - //TEST(test_crc64_ecma_add_range_via_iterator) - //{ - // std::string data("123456789"); + //************************************************************************* + TEST(test_crc64_ecma_add_range_via_iterator) + { + std::string data("123456789"); - // etl::crc::crc64_ecma crc_calculator; + etl::crc64_ecma crc_calculator; - // std::copy(data.begin(), data.end(), crc_calculator.input()); + std::copy(data.begin(), data.end(), crc_calculator.input()); - // uint64_t crc = crc_calculator.value(); + uint64_t crc = crc_calculator.value(); - // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - //} + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } - ////************************************************************************* - //TEST(test_crc64_ecma_add_range_endian) - //{ - // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - // std::vector data2 = { 0x04030201, 0x08070605 }; - // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + //************************************************************************* + TEST(test_crc64_ecma_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - // uint64_t crc1 = etl::crc::crc64_ecma(data1.begin(), data1.end()); - // uint64_t crc2 = etl::crc::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - // CHECK_EQUAL(crc1, crc2); + uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); + uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); - // uint64_t crc3 = etl::crc::crc64_ecma(data3.rbegin(), data3.rend()); - // CHECK_EQUAL(crc1, crc3); - //} + uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } }; } diff --git a/test/test_crc_table4.cpp b/test/test_crc_table4.cpp index 6b22fdf6..1f8de228 100644 --- a/test/test_crc_table4.cpp +++ b/test/test_crc_table4.cpp @@ -1,1259 +1,1257 @@ -///****************************************************************************** -//The MIT License(MIT) -// -//Embedded Template Library. -//https://github.com/ETLCPP/etl -//https://www.etlcpp.com -// -//Copyright(c) 2014 jwellbelove -// -//Permission is hereby granted, free of charge, to any person obtaining a copy -//of this software and associated documentation files(the "Software"), to deal -//in the Software without restriction, including without limitation the rights -//to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -//copies of the Software, and to permit persons to whom the Software is -//furnished to do so, subject to the following conditions : -// -//The above copyright notice and this permission notice shall be included in all -//copies or substantial portions of the Software. -// -//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -//SOFTWARE. -//******************************************************************************/ -// -//#include "unit_test_framework.h" -// -//#include -//#include -//#include -//#include -// -//#include "etl/experimental/crc8_ccitt.h" -//#include "etl/experimental/crc8_rohc.h" -////#include "etl/experimental/crc16.h" -////#include "etl/crc16.h" -////#include "etl/crc16_ccitt.h" -////#include "etl/crc16_aug_ccitt.h" -////#include "etl/crc16_kermit.h" -////#include "etl/crc16_modbus.h" -////#include "etl/crc16_usb.h" -////#include "etl/crc16_xmodem.h" -////#include "etl/crc16_genibus.h" -////#include "etl/crc16_x25.h" -////#include "etl/crc32.h" -////#include "etl/crc32_c.h" -////#include "etl/crc32_bzip2.h" -////#include "etl/crc32_mpeg2.h" -////#include "etl/crc32_posix.h" -////#include "etl/crc64_ecma.h" -// -////***************************************************************************** -//// The results for these tests were created from https://crccalc.com/ -////***************************************************************************** -// -//namespace -//{ -// SUITE(test_crc_experimental) -// { -// ////************************************************************************* -// //TEST(test_crc8_ccitt_constructor) -// //{ -// // std::string data("123456789"); -// -// // uint8_t crc = etl::crc::crc8_ccitt_t4(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xF4, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_ccitt_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_ccitt_t4 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint8_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xF4, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_ccitt_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_ccitt_t4 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint8_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xF4, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_ccitt_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_ccitt_t4 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint8_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xF4, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_ccitt_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); -// // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(int(crc1), int(crc2)); -// -// // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(int(crc1), int(crc3)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_constructor) -// //{ -// // std::string data("123456789"); -// -// // uint8_t crc = etl::crc::crc8_rohc(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xD0, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_rohc crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint8_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xD0, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_rohc crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint8_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xD0, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc8_rohc crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint8_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xD0, int(crc)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc8_rohc_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); -// // uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(int(crc1), int(crc2)); -// -// // uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(int(crc1), int(crc3)); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc::crc16(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xBB3D, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc16 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xBB3D, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc16 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xBB3D, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc::crc16 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xBB3D, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x29B1, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_ccitt crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x29B1, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_ccitt crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x29B1, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_ccitt crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x29B1, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_ccitt_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x2189, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_kermit crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x2189, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_kermit crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x2189, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_kermit crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x2189, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_kermit_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x4B37, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_modbus crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x4B37, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_modbus crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x4B37, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_modbus crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x4B37, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_modbus_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_usb(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xB4C8, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_usb crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xB4C8, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_usb crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xB4C8, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_usb crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xB4C8, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_usb_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x31C3, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_xmodem crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x31C3, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_xmodem crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x31C3, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_xmodem crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x31C3, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_xmodem_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xE5CC, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_aug_ccitt crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xE5CC, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_aug_ccitt crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xE5CC, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_aug_ccitt crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xE5CC, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_aug_ccitt_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xD64E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_genibus crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0xD64E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_genibus crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xD64E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_genibus crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xD64E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_genibus_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25) -// //{ -// // std::string data("123456789"); -// -// // uint16_t crc = etl::crc16_x25(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x906E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_x25 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint16_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x906E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_x25 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x906E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc16_x25 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint16_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x906E, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc16_x25_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); -// // uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xCBF43926, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0xCBF43926, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xCBF43926, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xCBF43926, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32_c(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xE3069283, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_c crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0xE3069283, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_c crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xE3069283, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_c crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xE3069283, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_c_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); -// -// // CHECK_EQUAL(0xFC891918, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_bzip2 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0xFC891918, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_bzip2 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xFC891918, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_bzip2 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0xFC891918, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_bzip2_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32_posix(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x765E7680, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_posix crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0x765E7680, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_posix crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x765E7680, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_posix crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x765E7680, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_posix_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2) -// //{ -// // std::string data("123456789"); -// -// // uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x0376E6E7, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_mpeg2 crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint32_t crc = crc_calculator; -// -// -// // CHECK_EQUAL(0x0376E6E7, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_mpeg2 crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x0376E6E7, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc32_mpeg2 crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint32_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x0376E6E7, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc32_mpeg2_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); -// // uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma) -// //{ -// // std::string data("123456789"); -// -// // uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); -// -// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma_add_values) -// //{ -// // std::string data("123456789"); -// -// // etl::crc64_ecma crc_calculator; -// -// // for (size_t i = 0; i < data.size(); ++i) -// // { -// // crc_calculator.add(data[i]); -// // } -// -// // uint64_t crc = crc_calculator; -// -// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma_add_range) -// //{ -// // std::string data("123456789"); -// -// // etl::crc64_ecma crc_calculator; -// -// // crc_calculator.add(data.begin(), data.end()); -// -// // uint64_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma_add_range_via_iterator) -// //{ -// // std::string data("123456789"); -// -// // etl::crc64_ecma crc_calculator; -// -// // std::copy(data.begin(), data.end(), crc_calculator.input()); -// -// // uint64_t crc = crc_calculator.value(); -// -// // CHECK_EQUAL(0x6C40DF5F0B497347U, crc); -// //} -// -// ////************************************************************************* -// //TEST(test_crc64_ecma_add_range_endian) -// //{ -// // std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; -// // std::vector data2 = { 0x04030201, 0x08070605 }; -// // std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; -// -// // uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); -// // uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); -// // CHECK_EQUAL(crc1, crc2); -// -// // uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); -// // CHECK_EQUAL(crc1, crc3); -// //} -// }; -//} -// +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_ccitt.h" +#include "etl/crc8_rohc.h" +#include "etl/crc16.h" +#include "etl/crc16_aug_ccitt.h" +#include "etl/crc16_ccitt.h" +#include "etl/crc16_kermit.h" +#include "etl/crc16_modbus.h" +#include "etl/crc16_usb.h" +#include "etl/crc16_genibus.h" +#include "etl/crc16_x25.h" +#include "etl/crc16_xmodem.h" +#include "etl/crc32.h" +#include "etl/crc32_c.h" +#include "etl/crc32_bzip2.h" +#include "etl/crc32_mpeg2.h" +#include "etl/crc32_posix.h" +#include "etl/crc64_ecma.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_t4_experimental) + { + //************************************************************************* + TEST(test_crc8_ccitt_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_ccitt_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc8_ccitt_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc8_ccitt_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_ccitt_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_ccitt_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_ccitt_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_ccitt_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + TEST(test_crc8_rohc_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_rohc_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_values) + { + std::string data("123456789"); + + etl::crc8_rohc_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_range) + { + std::string data("123456789"); + + etl::crc8_rohc_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_rohc_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_rohc_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_rohc_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_rohc_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + TEST(test_crc16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_values) + { + std::string data("123456789"); + + etl::crc16_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range) + { + std::string data("123456789"); + + etl::crc16_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3D, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_ccitt) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_ccitt_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc16_ccitt_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc16_ccitt_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_ccitt_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_ccitt_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_ccitt_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_ccitt_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_kermit) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_kermit_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_values) + { + std::string data("123456789"); + + etl::crc16_kermit_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range) + { + std::string data("123456789"); + + etl::crc16_kermit_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_kermit_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_kermit_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_kermit_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_kermit_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_modbus) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_modbus_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_values) + { + std::string data("123456789"); + + etl::crc16_modbus_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range) + { + std::string data("123456789"); + + etl::crc16_modbus_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_modbus_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_modbus_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_modbus_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_modbus_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_usb) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_usb_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_values) + { + std::string data("123456789"); + + etl::crc16_usb_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range) + { + std::string data("123456789"); + + etl::crc16_usb_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_usb_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_usb_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_usb_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_usb_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_xmodem) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_xmodem_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_values) + { + std::string data("123456789"); + + etl::crc16_xmodem_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range) + { + std::string data("123456789"); + + etl::crc16_xmodem_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_xmodem_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_xmodem_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_xmodem_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_xmodem_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_aug_ccitt_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CC, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_aug_ccitt_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_aug_ccitt_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_aug_ccitt_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_genibus) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_genibus_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_values) + { + std::string data("123456789"); + + etl::crc16_genibus_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range) + { + std::string data("123456789"); + + etl::crc16_genibus_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_genibus_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64E, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_genibus_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_genibus_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_genibus_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc16_x25) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_x25_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_values) + { + std::string data("123456789"); + + etl::crc16_x25_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range) + { + std::string data("123456789"); + + etl::crc16_x25_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_x25_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906E, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_x25_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_x25_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_x25_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_values) + { + std::string data("123456789"); + + etl::crc32_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range) + { + std::string data("123456789"); + + etl::crc32_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32_c) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_c_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xE3069283, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_values) + { + std::string data("123456789"); + + etl::crc32_c_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + + CHECK_EQUAL(0xE3069283, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_range) + { + std::string data("123456789"); + + etl::crc32_c_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_c_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_c_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_c_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_c_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32_bzip2) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_bzip2_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xFC891918, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_values) + { + std::string data("123456789"); + + etl::crc32_bzip2_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + + CHECK_EQUAL(0xFC891918, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_range) + { + std::string data("123456789"); + + etl::crc32_bzip2_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_bzip2_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_bzip2_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_bzip2_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_bzip2_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32_posix) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_posix_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x765E7680, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_values) + { + std::string data("123456789"); + + etl::crc32_posix_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x765E7680, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_range) + { + std::string data("123456789"); + + etl::crc32_posix_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_posix_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_posix_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_posix_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_posix_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc32_mpeg2) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_mpeg2_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x0376E6E7, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_values) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + + CHECK_EQUAL(0x0376E6E7, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_range) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_mpeg2_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_mpeg2_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_mpeg2_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + TEST(test_crc64_ecma) + { + std::string data("123456789"); + + uint64_t crc = etl::crc64_ecma_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_values) + { + std::string data("123456789"); + + etl::crc64_ecma_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint64_t crc = crc_calculator; + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range) + { + std::string data("123456789"); + + etl::crc64_ecma_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc64_ecma_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint64_t crc1 = etl::crc64_ecma_t4(data1.begin(), data1.end()); + uint64_t crc2 = etl::crc64_ecma_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint64_t crc3 = etl::crc64_ecma_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 41f6646b..5ce03d1b 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1258,39 +1258,26 @@ + + + + + + - - - - - - - - - - - - - - - - - - - @@ -1326,12 +1313,8 @@ - - - - - - + + @@ -1425,12 +1408,6 @@ - - - - - - @@ -3838,7 +3815,6 @@ - diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 43169276..6f9bfe66 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -106,9 +106,6 @@ {562466b5-677d-4448-9e9e-f70805cd71ad} - - {016bd5a6-e277-4aba-8b28-28a9f1348473} - @@ -168,21 +165,6 @@ ETL\Containers - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - ETL\Maths @@ -204,9 +186,6 @@ ETL\Containers - - ETL\Maths - ETL\Utilities @@ -513,9 +492,6 @@ ETL\Utilities - - ETL\Maths - Header Files @@ -654,9 +630,6 @@ ETL\Frameworks - - ETL\Maths - ETL\Maths @@ -756,51 +729,6 @@ ETL\Containers - - ETL\Private - - - ETL\Private - - - ETL\Private - - - ETL\Private - - - ETL\Private - - - ETL\Private - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - - - ETL\Maths - ETL\Profiles @@ -987,62 +915,62 @@ Source Files\Sanity Checks\C++17 - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Maths - - ETL\Maths\Experimental + + ETL\Private - - ETL\Maths\Experimental + + ETL\Private @@ -1088,9 +1016,6 @@ Source Files - - Source Files - Source Files From 47f6113b97679bc7a40ac78526bf770ee3e16a65 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 27 Mar 2021 09:28:19 +0000 Subject: [PATCH 6/8] Intermediate commit - Passing all tests --- include/etl/crc8_ccitt.h | 4 +- include/etl/crc8_rohc.h | 4 +- include/etl/private/crc_implementation.h | 100 ++++++++--------------- include/etl/private/crc_parameters.h | 35 +++++++- 4 files changed, 70 insertions(+), 73 deletions(-) diff --git a/include/etl/crc8_ccitt.h b/include/etl/crc8_ccitt.h index 4ebe9277..80c7ec8e 100644 --- a/include/etl/crc8_ccitt.h +++ b/include/etl/crc8_ccitt.h @@ -28,8 +28,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_CRC8_CCITT_EXP_INCLUDED -#define ETL_CRC8_CCITT_EXP_INCLUDED +#ifndef ETL_CRC8_CCITT_INCLUDED +#define ETL_CRC8_CCITT_INCLUDED #include "platform.h" #include "private/crc_implementation.h" diff --git a/include/etl/crc8_rohc.h b/include/etl/crc8_rohc.h index de15247c..79588eba 100644 --- a/include/etl/crc8_rohc.h +++ b/include/etl/crc8_rohc.h @@ -28,8 +28,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_CRC8_ROHC_EXP_INCLUDED -#define ETL_CRC8_ROHC_EXP_INCLUDED +#ifndef ETL_CRC8_ROHC_INCLUDED +#define ETL_CRC8_ROHC_INCLUDED #include "platform.h" #include "private/crc_implementation.h" diff --git a/include/etl/private/crc_implementation.h b/include/etl/private/crc_implementation.h index 8cdd1722..491a199c 100644 --- a/include/etl/private/crc_implementation.h +++ b/include/etl/private/crc_implementation.h @@ -1,5 +1,35 @@ +///\file -#pragma once +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC_IMPLEMENTATION_INCLUDED +#define ETL_CRC_IMPLEMENTATION_INCLUDED #include "../platform.h" #include "../frame_check_sequence.h" @@ -109,60 +139,6 @@ namespace etl crc_entry::value>::value; }; - ////************************************************************************* - //// Accumulator_Bits > Chunk_Bits and not reflected - //template - //typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && !Reflect, TAccumulator>::type - // crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - //{ - // size_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; - - // crc <<= Chunk_Bits; - // crc ^= table[index]; - - // return crc; - //} - - ////************************************************************************* - //// Accumulator_Bits > Chunk_Bits and reflected - //template - //typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && Reflect, TAccumulator>::type - // crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - //{ - // size_t index = size_t((crc & Chunk_Mask) ^ value); - - // crc >>= Chunk_Bits; - // crc ^= table[index]; - - // return crc; - //} - - ////************************************************************************* - //// Accumulator_Bits == Chunk_Bits and not reflected - //template - //typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && !Reflect, TAccumulator>::type - // crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - //{ - // size_t index = size_t((crc >> (Accumulator_Bits - Chunk_Bits)) ^ value); - - // crc = table[index]; - - // return crc; - //} - - ////************************************************************************* - //// Accumulator_Bits == Chunk_Bits and reflected - //template - //typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && Reflect, TAccumulator>::type - // crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) - //{ - // size_t index = size_t((crc & Chunk_Mask) ^ value); - - // crc = table[index]; - - // return crc; - //} - //***************************************************************************** // CRC Policies. //***************************************************************************** @@ -191,12 +167,6 @@ namespace etl //************************************************************************* static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) { - //// Extract the most significant nibble of the crc and xor with the value nibble. - //size_t index = size_t((crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value); - - //crc <<= Chunk_Bits; - //crc ^= table[index]; - value &= Chunk_Mask; if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) @@ -536,12 +506,6 @@ namespace etl //************************************************************************* static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) { - //// Extract the most significant nibble of the crc and xor with the value nibble. - //size_t index = size_t((crc >> (etl::integral_limits::bits - Chunk_Bits)) ^ value); - - //crc <<= Chunk_Bits; - //crc ^= table[index]; - value &= Chunk_Mask; if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) @@ -754,3 +718,5 @@ namespace etl } }; } + +#endif diff --git a/include/etl/private/crc_parameters.h b/include/etl/private/crc_parameters.h index f1c4796c..b90ba3de 100644 --- a/include/etl/private/crc_parameters.h +++ b/include/etl/private/crc_parameters.h @@ -1,4 +1,35 @@ -#pragma once +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC_PARAMETERS_INCLUDED +#define ETL_CRC_PARAMETERS_INCLUDED #include "../platform.h" #include "../integral_limits.h" @@ -71,4 +102,4 @@ namespace etl } } - +#endif From 70f0b92a0daafab460686df2463f5e26323ee3ff Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 29 Mar 2021 13:54:12 +0100 Subject: [PATCH 7/8] CRC updates --- include/etl/crc16_a.h | 78 ++ include/etl/crc16_arc.h | 78 ++ include/etl/crc16_buypass.h | 78 ++ include/etl/crc16_cdma2000.h | 78 ++ include/etl/crc16_dds110.h | 78 ++ include/etl/crc16_dect_r.h | 78 ++ include/etl/crc16_dect_x.h | 78 ++ include/etl/crc16_dnp.h | 78 ++ include/etl/crc16_en13757.h | 78 ++ include/etl/crc16_maxim.h | 78 ++ include/etl/crc16_mcrf4xx.h | 78 ++ include/etl/crc16_profibus.h | 78 ++ include/etl/crc16_riello.h | 78 ++ include/etl/crc16_t10dif.h | 78 ++ include/etl/crc16_teledisk.h | 78 ++ include/etl/crc16_tms37157.h | 78 ++ include/etl/crc32_d.h | 78 ++ include/etl/crc32_jamcrc.h | 78 ++ include/etl/crc32_q.h | 78 ++ include/etl/crc32_xfer.h | 78 ++ include/etl/crc8_cdma2000.h | 79 ++ include/etl/crc8_darc.h | 79 ++ include/etl/crc8_dvbs2.h | 79 ++ include/etl/crc8_ebu.h | 79 ++ include/etl/crc8_icode.h | 79 ++ include/etl/crc8_itu.h | 79 ++ include/etl/crc8_maxim.h | 79 ++ include/etl/crc8_wcdma.h | 79 ++ include/etl/private/crc_implementation.h | 1044 +++++++++--------- include/etl/private/crc_parameters.h | 53 +- test/test_crc16.cpp | 263 +++++ test/test_crc16_a.cpp | 263 +++++ test/test_crc16_aug_ccitt.cpp | 263 +++++ test/test_crc16_buypass.cpp | 263 +++++ test/test_crc16_ccitt.cpp | 263 +++++ test/test_crc16_cdma2000.cpp | 263 +++++ test/test_crc16_dds110.cpp | 263 +++++ test/test_crc16_dect_r.cpp | 263 +++++ test/test_crc16_dect_x.cpp | 263 +++++ test/test_crc16_dnp.cpp | 263 +++++ test/test_crc16_en13757.cpp | 263 +++++ test/test_crc16_genibus.cpp | 263 +++++ test/test_crc16_kermit.cpp | 263 +++++ test/test_crc16_maxim.cpp | 263 +++++ test/test_crc16_mcrf4xx.cpp | 263 +++++ test/test_crc16_modbus.cpp | 263 +++++ test/test_crc16_profibus.cpp | 263 +++++ test/test_crc16_riello.cpp | 263 +++++ test/test_crc16_t10dif.cpp | 263 +++++ test/test_crc16_teledisk.cpp | 263 +++++ test/test_crc16_tms37157.cpp | 263 +++++ test/test_crc16_usb.cpp | 263 +++++ test/test_crc16_x25.cpp | 263 +++++ test/test_crc16_xmodem.cpp | 263 +++++ test/test_crc32.cpp | 263 +++++ test/test_crc32_bzip2.cpp | 263 +++++ test/test_crc32_c.cpp | 263 +++++ test/test_crc32_d.cpp | 263 +++++ test/test_crc32_jamcrc.cpp | 263 +++++ test/test_crc32_mpeg2.cpp | 263 +++++ test/test_crc32_posix.cpp | 263 +++++ test/test_crc32_q.cpp | 263 +++++ test/test_crc32_xfer.cpp | 263 +++++ test/test_crc64_ecma.cpp | 263 +++++ test/test_crc8_ccitt.cpp | 263 +++++ test/test_crc8_cdma2000.cpp | 263 +++++ test/test_crc8_darc.cpp | 263 +++++ test/test_crc8_dvbs2.cpp | 263 +++++ test/test_crc8_ebu.cpp | 263 +++++ test/test_crc8_icode.cpp | 263 +++++ test/test_crc8_itu.cpp | 263 +++++ test/test_crc8_maxim.cpp | 263 +++++ test/test_crc8_rohc.cpp | 263 +++++ test/test_crc8_wcdma.cpp | 263 +++++ test/test_crc_table16.cpp | 1257 --------------------- test/test_crc_table256.cpp | 1258 ---------------------- test/test_crc_table4.cpp | 1257 --------------------- test/vs2019/etl.vcxproj | 66 +- test/vs2019/etl.vcxproj.filters | 174 ++- 79 files changed, 14531 insertions(+), 4342 deletions(-) create mode 100644 include/etl/crc16_a.h create mode 100644 include/etl/crc16_arc.h create mode 100644 include/etl/crc16_buypass.h create mode 100644 include/etl/crc16_cdma2000.h create mode 100644 include/etl/crc16_dds110.h create mode 100644 include/etl/crc16_dect_r.h create mode 100644 include/etl/crc16_dect_x.h create mode 100644 include/etl/crc16_dnp.h create mode 100644 include/etl/crc16_en13757.h create mode 100644 include/etl/crc16_maxim.h create mode 100644 include/etl/crc16_mcrf4xx.h create mode 100644 include/etl/crc16_profibus.h create mode 100644 include/etl/crc16_riello.h create mode 100644 include/etl/crc16_t10dif.h create mode 100644 include/etl/crc16_teledisk.h create mode 100644 include/etl/crc16_tms37157.h create mode 100644 include/etl/crc32_d.h create mode 100644 include/etl/crc32_jamcrc.h create mode 100644 include/etl/crc32_q.h create mode 100644 include/etl/crc32_xfer.h create mode 100644 include/etl/crc8_cdma2000.h create mode 100644 include/etl/crc8_darc.h create mode 100644 include/etl/crc8_dvbs2.h create mode 100644 include/etl/crc8_ebu.h create mode 100644 include/etl/crc8_icode.h create mode 100644 include/etl/crc8_itu.h create mode 100644 include/etl/crc8_maxim.h create mode 100644 include/etl/crc8_wcdma.h create mode 100644 test/test_crc16.cpp create mode 100644 test/test_crc16_a.cpp create mode 100644 test/test_crc16_aug_ccitt.cpp create mode 100644 test/test_crc16_buypass.cpp create mode 100644 test/test_crc16_ccitt.cpp create mode 100644 test/test_crc16_cdma2000.cpp create mode 100644 test/test_crc16_dds110.cpp create mode 100644 test/test_crc16_dect_r.cpp create mode 100644 test/test_crc16_dect_x.cpp create mode 100644 test/test_crc16_dnp.cpp create mode 100644 test/test_crc16_en13757.cpp create mode 100644 test/test_crc16_genibus.cpp create mode 100644 test/test_crc16_kermit.cpp create mode 100644 test/test_crc16_maxim.cpp create mode 100644 test/test_crc16_mcrf4xx.cpp create mode 100644 test/test_crc16_modbus.cpp create mode 100644 test/test_crc16_profibus.cpp create mode 100644 test/test_crc16_riello.cpp create mode 100644 test/test_crc16_t10dif.cpp create mode 100644 test/test_crc16_teledisk.cpp create mode 100644 test/test_crc16_tms37157.cpp create mode 100644 test/test_crc16_usb.cpp create mode 100644 test/test_crc16_x25.cpp create mode 100644 test/test_crc16_xmodem.cpp create mode 100644 test/test_crc32.cpp create mode 100644 test/test_crc32_bzip2.cpp create mode 100644 test/test_crc32_c.cpp create mode 100644 test/test_crc32_d.cpp create mode 100644 test/test_crc32_jamcrc.cpp create mode 100644 test/test_crc32_mpeg2.cpp create mode 100644 test/test_crc32_posix.cpp create mode 100644 test/test_crc32_q.cpp create mode 100644 test/test_crc32_xfer.cpp create mode 100644 test/test_crc64_ecma.cpp create mode 100644 test/test_crc8_ccitt.cpp create mode 100644 test/test_crc8_cdma2000.cpp create mode 100644 test/test_crc8_darc.cpp create mode 100644 test/test_crc8_dvbs2.cpp create mode 100644 test/test_crc8_ebu.cpp create mode 100644 test/test_crc8_icode.cpp create mode 100644 test/test_crc8_itu.cpp create mode 100644 test/test_crc8_maxim.cpp create mode 100644 test/test_crc8_rohc.cpp create mode 100644 test/test_crc8_wcdma.cpp delete mode 100644 test/test_crc_table16.cpp delete mode 100644 test/test_crc_table256.cpp delete mode 100644 test/test_crc_table4.cpp diff --git a/include/etl/crc16_a.h b/include/etl/crc16_a.h new file mode 100644 index 00000000..c9bf4fa4 --- /dev/null +++ b/include/etl/crc16_a.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_A_INCLUDED +#define ETL_CRC16_A_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_a 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_a_t = etl::crc_type; +#else + template + class crc16_a_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_a_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_a_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_a_t<256U> crc16_a_t256; + typedef etl::crc16_a_t<16U> crc16_a_t16; + typedef etl::crc16_a_t<4U> crc16_a_t4; + typedef crc16_a_t256 crc16_a; +} +#endif diff --git a/include/etl/crc16_arc.h b/include/etl/crc16_arc.h new file mode 100644 index 00000000..b60b667c --- /dev/null +++ b/include/etl/crc16_arc.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_ARC_INCLUDED +#define ETL_CRC16_ARC_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_arc 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_arc_t = etl::crc_type; +#else + template + class crc16_arc_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_arc_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_arc_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_arc_t<256U> crc16_arc_t256; + typedef etl::crc16_arc_t<16U> crc16_arc_t16; + typedef etl::crc16_arc_t<4U> crc16_arc_t4; + typedef crc16_arc_t256 crc16_arc; +} +#endif diff --git a/include/etl/crc16_buypass.h b/include/etl/crc16_buypass.h new file mode 100644 index 00000000..a8315e21 --- /dev/null +++ b/include/etl/crc16_buypass.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_BUYPASS_INCLUDED +#define ETL_CRC16_BUYPASS_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_buypass 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_buypass_t = etl::crc_type; +#else + template + class crc16_buypass_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_buypass_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_buypass_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_buypass_t<256U> crc16_buypass_t256; + typedef etl::crc16_buypass_t<16U> crc16_buypass_t16; + typedef etl::crc16_buypass_t<4U> crc16_buypass_t4; + typedef crc16_buypass_t256 crc16_buypass; +} +#endif diff --git a/include/etl/crc16_cdma2000.h b/include/etl/crc16_cdma2000.h new file mode 100644 index 00000000..3a5b2b77 --- /dev/null +++ b/include/etl/crc16_cdma2000.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_CDMA2000_INCLUDED +#define ETL_CRC16_CDMA2000_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_cdma2000 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_cdma2000_t = etl::crc_type; +#else + template + class crc16_cdma2000_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_cdma2000_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_cdma2000_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_cdma2000_t<256U> crc16_cdma2000_t256; + typedef etl::crc16_cdma2000_t<16U> crc16_cdma2000_t16; + typedef etl::crc16_cdma2000_t<4U> crc16_cdma2000_t4; + typedef crc16_cdma2000_t256 crc16_cdma2000; +} +#endif diff --git a/include/etl/crc16_dds110.h b/include/etl/crc16_dds110.h new file mode 100644 index 00000000..e3dbbf8e --- /dev/null +++ b/include/etl/crc16_dds110.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_DDS110_INCLUDED +#define ETL_CRC16_DDS110_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_dds110 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_dds110_t = etl::crc_type; +#else + template + class crc16_dds110_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_dds110_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_dds110_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_dds110_t<256U> crc16_dds110_t256; + typedef etl::crc16_dds110_t<16U> crc16_dds110_t16; + typedef etl::crc16_dds110_t<4U> crc16_dds110_t4; + typedef crc16_dds110_t256 crc16_dds110; +} +#endif diff --git a/include/etl/crc16_dect_r.h b/include/etl/crc16_dect_r.h new file mode 100644 index 00000000..b1240d50 --- /dev/null +++ b/include/etl/crc16_dect_r.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_DECT_R_INCLUDED +#define ETL_CRC16_DECT_R_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_dect_r 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_dect_r_t = etl::crc_type; +#else + template + class crc16_dect_r_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_dect_r_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_dect_r_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_dect_r_t<256U> crc16_dect_r_t256; + typedef etl::crc16_dect_r_t<16U> crc16_dect_r_t16; + typedef etl::crc16_dect_r_t<4U> crc16_dect_r_t4; + typedef crc16_dect_r_t256 crc16_dect_r; +} +#endif diff --git a/include/etl/crc16_dect_x.h b/include/etl/crc16_dect_x.h new file mode 100644 index 00000000..27cecd70 --- /dev/null +++ b/include/etl/crc16_dect_x.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_DECT_X_INCLUDED +#define ETL_CRC16_DECT_X_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_dect_x 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_dect_x_t = etl::crc_type; +#else + template + class crc16_dect_x_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_dect_x_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_dect_x_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_dect_x_t<256U> crc16_dect_x_t256; + typedef etl::crc16_dect_x_t<16U> crc16_dect_x_t16; + typedef etl::crc16_dect_x_t<4U> crc16_dect_x_t4; + typedef crc16_dect_x_t256 crc16_dect_x; +} +#endif diff --git a/include/etl/crc16_dnp.h b/include/etl/crc16_dnp.h new file mode 100644 index 00000000..a347ccd3 --- /dev/null +++ b/include/etl/crc16_dnp.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_DNP_INCLUDED +#define ETL_CRC16_DNP_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_dnp 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_dnp_t = etl::crc_type; +#else + template + class crc16_dnp_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_dnp_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_dnp_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_dnp_t<256U> crc16_dnp_t256; + typedef etl::crc16_dnp_t<16U> crc16_dnp_t16; + typedef etl::crc16_dnp_t<4U> crc16_dnp_t4; + typedef crc16_dnp_t256 crc16_dnp; +} +#endif diff --git a/include/etl/crc16_en13757.h b/include/etl/crc16_en13757.h new file mode 100644 index 00000000..1cb217fc --- /dev/null +++ b/include/etl/crc16_en13757.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_EN13757_INCLUDED +#define ETL_CRC16_EN13757_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_en13757 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_en13757_t = etl::crc_type; +#else + template + class crc16_en13757_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_en13757_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_en13757_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_en13757_t<256U> crc16_en13757_t256; + typedef etl::crc16_en13757_t<16U> crc16_en13757_t16; + typedef etl::crc16_en13757_t<4U> crc16_en13757_t4; + typedef crc16_en13757_t256 crc16_en13757; +} +#endif diff --git a/include/etl/crc16_maxim.h b/include/etl/crc16_maxim.h new file mode 100644 index 00000000..ef3a2bca --- /dev/null +++ b/include/etl/crc16_maxim.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_MAXIM_INCLUDED +#define ETL_CRC16_MAXIM_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +//\defgroup crc16_maxim 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_maxim_t = etl::crc_type; +#else + template + class crc16_maxim_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_maxim_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_maxim_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_maxim_t<256U> crc16_maxim_t256; + typedef etl::crc16_maxim_t<16U> crc16_maxim_t16; + typedef etl::crc16_maxim_t<4U> crc16_maxim_t4; + typedef crc16_maxim_t256 crc16_maxim; +} +#endif diff --git a/include/etl/crc16_mcrf4xx.h b/include/etl/crc16_mcrf4xx.h new file mode 100644 index 00000000..24012377 --- /dev/null +++ b/include/etl/crc16_mcrf4xx.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_MCRF4XX_INCLUDED +#define ETL_CRC16_MCRF4XX_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_mcrf4xx 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_mcrf4xx_t = etl::crc_type; +#else + template + class crc16_mcrf4xx_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_mcrf4xx_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_mcrf4xx_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_mcrf4xx_t<256U> crc16_mcrf4xx_t256; + typedef etl::crc16_mcrf4xx_t<16U> crc16_mcrf4xx_t16; + typedef etl::crc16_mcrf4xx_t<4U> crc16_mcrf4xx_t4; + typedef crc16_mcrf4xx_t256 crc16_mcrf4xx; +} +#endif diff --git a/include/etl/crc16_profibus.h b/include/etl/crc16_profibus.h new file mode 100644 index 00000000..275f5bb6 --- /dev/null +++ b/include/etl/crc16_profibus.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_PROFIBUS_INCLUDED +#define ETL_CRC16_PROFIBUS_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_profibus 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_profibus_t = etl::crc_type; +#else + template + class crc16_profibus_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_profibus_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_profibus_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_profibus_t<256U> crc16_profibus_t256; + typedef etl::crc16_profibus_t<16U> crc16_profibus_t16; + typedef etl::crc16_profibus_t<4U> crc16_profibus_t4; + typedef crc16_profibus_t256 crc16_profibus; +} +#endif diff --git a/include/etl/crc16_riello.h b/include/etl/crc16_riello.h new file mode 100644 index 00000000..65f99583 --- /dev/null +++ b/include/etl/crc16_riello.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_RIELLO_INCLUDED +#define ETL_CRC16_RIELLO_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_riello 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_riello_t = etl::crc_type; +#else + template + class crc16_riello_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_riello_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_riello_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_riello_t<256U> crc16_riello_t256; + typedef etl::crc16_riello_t<16U> crc16_riello_t16; + typedef etl::crc16_riello_t<4U> crc16_riello_t4; + typedef crc16_riello_t256 crc16_riello; +} +#endif diff --git a/include/etl/crc16_t10dif.h b/include/etl/crc16_t10dif.h new file mode 100644 index 00000000..1087c8cd --- /dev/null +++ b/include/etl/crc16_t10dif.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_T10DIF_INCLUDED +#define ETL_CRC16_T10DIF_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc16_t10dif 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_t10dif_t = etl::crc_type; +#else + template + class crc16_t10dif_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_t10dif_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_t10dif_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_t10dif_t<256U> crc16_t10dif_t256; + typedef etl::crc16_t10dif_t<16U> crc16_t10dif_t16; + typedef etl::crc16_t10dif_t<4U> crc16_t10dif_t4; + typedef crc16_t10dif_t256 crc16_t10dif; +} +#endif diff --git a/include/etl/crc16_teledisk.h b/include/etl/crc16_teledisk.h new file mode 100644 index 00000000..29e78eca --- /dev/null +++ b/include/etl/crc16_teledisk.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_TELEDISK_INCLUDED +#define ETL_CRC16_TELEDISK_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +//\defgroup crc16_teledisk 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_teledisk_t = etl::crc_type; +#else + template + class crc16_teledisk_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_teledisk_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_teledisk_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_teledisk_t<256U> crc16_teledisk_t256; + typedef etl::crc16_teledisk_t<16U> crc16_teledisk_t16; + typedef etl::crc16_teledisk_t<4U> crc16_teledisk_t4; + typedef crc16_teledisk_t256 crc16_teledisk; +} +#endif diff --git a/include/etl/crc16_tms37157.h b/include/etl/crc16_tms37157.h new file mode 100644 index 00000000..4af39380 --- /dev/null +++ b/include/etl/crc16_tms37157.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC16_TMS37157_INCLUDED +#define ETL_CRC16_TMS37157_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +//\defgroup crc16_tms37157 16 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc16_tms37157_t = etl::crc_type; +#else + template + class crc16_tms37157_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc16_tms37157_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc16_tms37157_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc16_tms37157_t<256U> crc16_tms37157_t256; + typedef etl::crc16_tms37157_t<16U> crc16_tms37157_t16; + typedef etl::crc16_tms37157_t<4U> crc16_tms37157_t4; + typedef crc16_tms37157_t256 crc16_tms37157; +} +#endif diff --git a/include/etl/crc32_d.h b/include/etl/crc32_d.h new file mode 100644 index 00000000..ca737f43 --- /dev/null +++ b/include/etl/crc32_d.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC32_D_INCLUDED +#define ETL_CRC32_D_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc32_d 32 bit CRC_D calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED + template + using crc32_d_t = etl::crc_type; +#else + template + class crc32_d_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_d_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_d_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc32_d_t<256U> crc32_d_t256; + typedef etl::crc32_d_t<16U> crc32_d_t16; + typedef etl::crc32_d_t<4U> crc32_d_t4; + typedef crc32_d_t256 crc32_d; +} +#endif diff --git a/include/etl/crc32_jamcrc.h b/include/etl/crc32_jamcrc.h new file mode 100644 index 00000000..dbe1701f --- /dev/null +++ b/include/etl/crc32_jamcrc.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC32_JAMCRC_INCLUDED +#define ETL_CRC32_JAMCRC_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc32_jamcrc 32 bit CRC_JAMCRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED + template + using crc32_jamcrc_t = etl::crc_type; +#else + template + class crc32_jamcrc_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_jamcrc_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_jamcrc_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc32_jamcrc_t<256U> crc32_jamcrc_t256; + typedef etl::crc32_jamcrc_t<16U> crc32_jamcrc_t16; + typedef etl::crc32_jamcrc_t<4U> crc32_jamcrc_t4; + typedef crc32_jamcrc_t256 crc32_jamcrc; +} +#endif diff --git a/include/etl/crc32_q.h b/include/etl/crc32_q.h new file mode 100644 index 00000000..41143dfe --- /dev/null +++ b/include/etl/crc32_q.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC32_D_INCLUDED +#define ETL_CRC32_D_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc32_q 32 bit CRC_Q calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED + template + using crc32_q_t = etl::crc_type; +#else + template + class crc32_q_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_q_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_q_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc32_q_t<256U> crc32_q_t256; + typedef etl::crc32_q_t<16U> crc32_q_t16; + typedef etl::crc32_q_t<4U> crc32_q_t4; + typedef crc32_q_t256 crc32_q; +} +#endif diff --git a/include/etl/crc32_xfer.h b/include/etl/crc32_xfer.h new file mode 100644 index 00000000..c8ef5f5f --- /dev/null +++ b/include/etl/crc32_xfer.h @@ -0,0 +1,78 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC32_XFER_INCLUDED +#define ETL_CRC32_XFER_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup crc32_xfer 32 bit CRC_Q calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED + template + using crc32_xfer_t = etl::crc_type; +#else + template + class crc32_xfer_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc32_xfer_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc32_xfer_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc32_xfer_t<256U> crc32_xfer_t256; + typedef etl::crc32_xfer_t<16U> crc32_xfer_t16; + typedef etl::crc32_xfer_t<4U> crc32_xfer_t4; + typedef crc32_xfer_t256 crc32_xfer; +} +#endif diff --git a/include/etl/crc8_cdma2000.h b/include/etl/crc8_cdma2000.h new file mode 100644 index 00000000..34567d8f --- /dev/null +++ b/include/etl/crc8_cdma2000.h @@ -0,0 +1,79 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_CDMA2000_INCLUDED +#define ETL_CRC8_CDMA2000_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup cdma2000 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_cdma2000_t = etl::crc_type; +#else + template + class crc8_cdma2000_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_cdma2000_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_cdma2000_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_cdma2000_t<256U> crc8_cdma2000_t256; + typedef etl::crc8_cdma2000_t<16U> crc8_cdma2000_t16; + typedef etl::crc8_cdma2000_t<4U> crc8_cdma2000_t4; + typedef crc8_cdma2000_t256 crc8_cdma2000; +} + +#endif diff --git a/include/etl/crc8_darc.h b/include/etl/crc8_darc.h new file mode 100644 index 00000000..464bdc21 --- /dev/null +++ b/include/etl/crc8_darc.h @@ -0,0 +1,79 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_DARC_INCLUDED +#define ETL_CRC8_DARC_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup darc 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_darc_t = etl::crc_type; +#else + template + class crc8_darc_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_darc_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_darc_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_darc_t<256U> crc8_darc_t256; + typedef etl::crc8_darc_t<16U> crc8_darc_t16; + typedef etl::crc8_darc_t<4U> crc8_darc_t4; + typedef crc8_darc_t256 crc8_darc; +} + +#endif diff --git a/include/etl/crc8_dvbs2.h b/include/etl/crc8_dvbs2.h new file mode 100644 index 00000000..0ae5b6a1 --- /dev/null +++ b/include/etl/crc8_dvbs2.h @@ -0,0 +1,79 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_DVBS2_INCLUDED +#define ETL_CRC8_DVBS2_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup dvbs2 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_dvbs2_t = etl::crc_type; +#else + template + class crc8_dvbs2_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_dvbs2_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_dvbs2_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_dvbs2_t<256U> crc8_dvbs2_t256; + typedef etl::crc8_dvbs2_t<16U> crc8_dvbs2_t16; + typedef etl::crc8_dvbs2_t<4U> crc8_dvbs2_t4; + typedef crc8_dvbs2_t256 crc8_dvbs2; +} + +#endif diff --git a/include/etl/crc8_ebu.h b/include/etl/crc8_ebu.h new file mode 100644 index 00000000..4caf7686 --- /dev/null +++ b/include/etl/crc8_ebu.h @@ -0,0 +1,79 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_EBU_INCLUDED +#define ETL_CRC8_EBU_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup ebu 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_ebu_t = etl::crc_type; +#else + template + class crc8_ebu_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_ebu_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_ebu_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_ebu_t<256U> crc8_ebu_t256; + typedef etl::crc8_ebu_t<16U> crc8_ebu_t16; + typedef etl::crc8_ebu_t<4U> crc8_ebu_t4; + typedef crc8_ebu_t256 crc8_ebu; +} + +#endif diff --git a/include/etl/crc8_icode.h b/include/etl/crc8_icode.h new file mode 100644 index 00000000..bfe21666 --- /dev/null +++ b/include/etl/crc8_icode.h @@ -0,0 +1,79 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_ICODE_INCLUDED +#define ETL_CRC8_ICODE_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup icode 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_icode_t = etl::crc_type; +#else + template + class crc8_icode_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_icode_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_icode_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_icode_t<256U> crc8_icode_t256; + typedef etl::crc8_icode_t<16U> crc8_icode_t16; + typedef etl::crc8_icode_t<4U> crc8_icode_t4; + typedef crc8_icode_t256 crc8_icode; +} + +#endif diff --git a/include/etl/crc8_itu.h b/include/etl/crc8_itu.h new file mode 100644 index 00000000..eb0a2803 --- /dev/null +++ b/include/etl/crc8_itu.h @@ -0,0 +1,79 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_ITU_INCLUDED +#define ETL_CRC8_ITU_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup itu 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_itu_t = etl::crc_type; +#else + template + class crc8_itu_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_itu_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_itu_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_itu_t<256U> crc8_itu_t256; + typedef etl::crc8_itu_t<16U> crc8_itu_t16; + typedef etl::crc8_itu_t<4U> crc8_itu_t4; + typedef crc8_itu_t256 crc8_itu; +} + +#endif diff --git a/include/etl/crc8_maxim.h b/include/etl/crc8_maxim.h new file mode 100644 index 00000000..84e5c4bf --- /dev/null +++ b/include/etl/crc8_maxim.h @@ -0,0 +1,79 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_MAXIM_INCLUDED +#define ETL_CRC8_MAXIM_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup maxim 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_maxim_t = etl::crc_type; +#else + template + class crc8_maxim_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_maxim_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_maxim_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_maxim_t<256U> crc8_maxim_t256; + typedef etl::crc8_maxim_t<16U> crc8_maxim_t16; + typedef etl::crc8_maxim_t<4U> crc8_maxim_t4; + typedef crc8_maxim_t256 crc8_maxim; +} + +#endif diff --git a/include/etl/crc8_wcdma.h b/include/etl/crc8_wcdma.h new file mode 100644 index 00000000..4ea1dc0b --- /dev/null +++ b/include/etl/crc8_wcdma.h @@ -0,0 +1,79 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC8_WCDMA_INCLUDED +#define ETL_CRC8_WCDMA_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup wcdma 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_CPP11_SUPPORTED && !ETL_CRC_FORCE_CPP03 + template + using crc8_wcdma_t = etl::crc_type; +#else + template + class crc8_wcdma_t : public etl::private_crc::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_wcdma_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_wcdma_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_wcdma_t<256U> crc8_wcdma_t256; + typedef etl::crc8_wcdma_t<16U> crc8_wcdma_t16; + typedef etl::crc8_wcdma_t<4U> crc8_wcdma_t4; + typedef crc8_wcdma_t256 crc8_wcdma; +} + +#endif diff --git a/include/etl/private/crc_implementation.h b/include/etl/private/crc_implementation.h index 491a199c..75c31509 100644 --- a/include/etl/private/crc_implementation.h +++ b/include/etl/private/crc_implementation.h @@ -35,6 +35,7 @@ SOFTWARE. #include "../frame_check_sequence.h" #include "../static_assert.h" #include "../binary.h" +#include "../type_traits.h" #include "stdint.h" @@ -49,94 +50,526 @@ namespace etl namespace private_crc { //***************************************************************************** - /// CRC Entry + /// CRC Partial Table Entry //***************************************************************************** - template - class crc_entry + template + class crc_partial_table_entry { private: - typedef typename TCrcParameters::accumulator_type accumulator_type; - - static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; - static ETL_CONSTANT accumulator_type Polynomial = TCrcParameters::Polynomial; - static ETL_CONSTANT bool Reflect = TCrcParameters::Reflect; - - static ETL_CONSTANT bool Do_Poly = Reflect ? (Entry & accumulator_type(1U)) != 0U - : (Entry & (accumulator_type(1U) << (Accumulator_Bits - 1U))) != 0U; + static ETL_CONSTANT bool Do_Poly = Reflect ? (Entry & TAccumulator(1U)) != 0U + : (Entry & (TAccumulator(1U) << (Accumulator_Bits - 1U))) != 0U; public: - static ETL_CONSTANT accumulator_type value = Reflect ? accumulator_type(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const::value : (Entry >> 1U)) - : accumulator_type(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); + static ETL_CONSTANT TAccumulator value = Reflect ? TAccumulator(Do_Poly ? (Entry >> 1U) ^ etl::reverse_bits_const::value : (Entry >> 1U)) + : TAccumulator(Do_Poly ? (Entry << 1U) ^ Polynomial : (Entry << 1U)); }; //***************************************************************************** /// CRC Table Entry //***************************************************************************** - template + template class crc_table_entry { ETL_STATIC_ASSERT((Chunk_Bits == 2U) || (Chunk_Bits == 4U) || (Chunk_Bits == 8U), "Chunk bits must be 2, 4 or 8"); }; //********************************* - // Chunk bit size of 8. - template - class crc_table_entry + // Chunk bit size of 2. + template + class crc_table_entry { public: - typedef typename TCrcParameters::accumulator_type accumulator_type; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 2U); + static ETL_CONSTANT TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); - static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 8U); - static ETL_CONSTANT accumulator_type Entry = TCrcParameters::Reflect ? accumulator_type(Index) : accumulator_type(accumulator_type(Index) << Shift_Bits); - - static ETL_CONSTANT accumulator_type value = crc_entry::value>::value>::value>::value>::value>::value>::value>::value; + static ETL_CONSTANT TAccumulator value = crc_partial_table_entry::value>::value; }; //********************************* // Chunk bit size of 4. - template - class crc_table_entry + template + class crc_table_entry { public: - typedef typename TCrcParameters::accumulator_type accumulator_type; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 4U); + static ETL_CONSTANT TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); - static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 4U); - static ETL_CONSTANT accumulator_type Entry = TCrcParameters::Reflect ? accumulator_type(Index) : accumulator_type(accumulator_type(Index) << Shift_Bits); - - static const accumulator_type value = crc_entry::value>::value>::value>::value; + static ETL_CONSTANT TAccumulator value = crc_partial_table_entry::value>::value>::value>::value; }; //********************************* - // Chunk bit size of 2. - template - class crc_table_entry + // Chunk bit size of 8. + template + class crc_table_entry { public: - typedef typename TCrcParameters::accumulator_type accumulator_type; + static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 8U); + static ETL_CONSTANT TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); - static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; - static ETL_CONSTANT size_t Shift_Bits = size_t(Accumulator_Bits - 2U); - static ETL_CONSTANT accumulator_type Entry = TCrcParameters::Reflect ? accumulator_type(Index) : accumulator_type(accumulator_type(Index) << Shift_Bits); + static ETL_CONSTANT TAccumulator value = crc_partial_table_entry::value>::value>::value>::value>::value>::value>::value>::value; + }; - static const accumulator_type value = crc_entry::value>::value; + //***************************************************************************** + /// CRC Update Chunk + //***************************************************************************** + + //********************************* + // Accumulator_Bits > Chunk_Bits + // Not Reflected + template + static + typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && !Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + value &= Chunk_Mask; + + uint8_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + + crc <<= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //********************************* + // Accumulator_Bits > Chunk_Bits + // Reflected + template + static + typename etl::enable_if<(Accumulator_Bits > Chunk_Bits) && Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + value &= Chunk_Mask; + + uint8_t index = (crc & Chunk_Mask) ^ value; + + crc >>= Chunk_Bits; + crc ^= table[index]; + + return crc; + } + + //********************************* + // Accumulator_Bits == Chunk_Bits + // Not Reflected + template + static + typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && !Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + value &= Chunk_Mask; + + uint8_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; + + crc = table[index]; + + return crc; + } + + //********************************* + // Accumulator_Bits == Chunk_Bits + // Reflected + template + static + typename etl::enable_if<(Accumulator_Bits == Chunk_Bits) && Reflect, TAccumulator>::type + crc_update_chunk(TAccumulator crc, uint8_t value, const TAccumulator table[]) + { + value &= Chunk_Mask; + + uint8_t index = (crc & Chunk_Mask) ^ value; + + crc = table[index]; + + return crc; + } + + //***************************************************************************** + // CRC Tables. + //***************************************************************************** + template + struct crc_table; + + //********************************* + // Table size of 4. + template + struct crc_table + { + //************************************************************************* + TAccumulator add(TAccumulator crc, uint8_t value) const + { + static ETL_CONSTANT TAccumulator table[4U] = + { + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value + }; + + if ETL_IF_CONSTEXPR(Reflect) + { + crc = crc_update_chunk(crc, value, table); + crc = crc_update_chunk(crc, (value >> (Chunk_Bits * 1U)), table); + crc = crc_update_chunk(crc, (value >> (Chunk_Bits * 2U)), table); + crc = crc_update_chunk(crc, (value >> (Chunk_Bits * 3U)), table); + } + else + { + crc = crc_update_chunk(crc, (value >> (Chunk_Bits * 3U)), table); + crc = crc_update_chunk(crc, (value >> (Chunk_Bits * 2U)), table); + crc = crc_update_chunk(crc, (value >> (Chunk_Bits * 1U)), table); + crc = crc_update_chunk(crc, value, table); + } + + return crc; + } + }; + + //********************************* + // Table size of 16. + template + struct crc_table + { + //************************************************************************* + TAccumulator add(TAccumulator crc, uint8_t value) const + { + static ETL_CONSTANT TAccumulator table[16U] = + { + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value + }; + + if ETL_IF_CONSTEXPR(Reflect) + { + crc = crc_update_chunk(crc, value, table); + crc = crc_update_chunk(crc, value >> Chunk_Bits, table); + } + else + { + crc = crc_update_chunk(crc, value >> Chunk_Bits, table); + crc = crc_update_chunk(crc, value, table); + } + + return crc; + } + }; + + //********************************* + // Table size of 256. + template + struct crc_table + { + //************************************************************************* + TAccumulator add(TAccumulator crc, uint8_t value) const + { + static ETL_CONSTANT TAccumulator table[256U] = + { + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value, + crc_table_entry::value + }; + + static ETL_CONSTANT size_t Index = 1; + + const size_t Shift_Bits = size_t(Accumulator_Bits - 8U); + const TAccumulator Entry = Reflect ? TAccumulator(Index) : TAccumulator(TAccumulator(Index) << Shift_Bits); + TAccumulator Table_Value = crc_partial_table_entry::value>::value>::value>::value>::value>::value>::value>::value; + + TAccumulator Polynomial_Value = Polynomial; + + crc = crc_update_chunk(crc, value, table); + + return crc; + } }; //***************************************************************************** @@ -148,331 +581,22 @@ namespace etl //********************************* // Policy for 256 entry table. template - struct crc_policy + struct crc_policy : public crc_table { typedef typename TCrcParameters::accumulator_type accumulator_type; typedef accumulator_type value_type; - static ETL_CONSTANT size_t Table_Size = 256U; - static ETL_CONSTANT uint8_t Chunk_Mask = Table_Size - 1U; - static ETL_CONSTANT size_t Chunk_Bits = 8U; - static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; - //************************************************************************* ETL_CONSTEXPR accumulator_type initial() const { - return TCrcParameters::Initial; - } - - //************************************************************************* - static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) - { - value &= Chunk_Mask; - - if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) - { - uint8_t index = (crc & Chunk_Mask) ^ value; - - // special case for when chunk size is same as accumulator size. - if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) - { - crc >>= Chunk_Bits; - crc ^= table[index]; - } - else - { - crc = table[index]; - } - - return crc; - } - else - { - // Extract the most significant nibble of the crc and xor with the value nibble - uint8_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; - - // special case for when chunk size is same as accumulator size. - if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) - { - crc <<= Chunk_Bits; - crc ^= table[index]; - } - else - { - crc = table[index]; - } - - return crc; - } - } - - //************************************************************************* - accumulator_type add(accumulator_type crc, uint8_t value) const - { - static ETL_CONSTANT accumulator_type table[Table_Size] = - { - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value - }; - - crc = update_chunk(crc, value, table); - //crc = crc_update_chunk(crc, value, table); - - return crc; + return TCrcParameters::Reflect ? etl::reverse_bits_const::value + : TCrcParameters::Initial; } //************************************************************************* @@ -485,101 +609,22 @@ namespace etl //********************************* // Policy for 16 entry table. template - struct crc_policy + struct crc_policy : public crc_table { typedef typename TCrcParameters::accumulator_type accumulator_type; typedef accumulator_type value_type; - static ETL_CONSTANT size_t Table_Size = 16U; - static ETL_CONSTANT uint8_t Chunk_Mask = Table_Size - 1U; - static ETL_CONSTANT size_t Chunk_Bits = 4U; - static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; - - typedef accumulator_type value_type; - //************************************************************************* ETL_CONSTEXPR accumulator_type initial() const { - return TCrcParameters::Initial; - } - - //************************************************************************* - static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) - { - value &= Chunk_Mask; - - if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) - { - uint8_t index = (crc & Chunk_Mask) ^ value; - - // special case for when chunk size is same as accumulator size. - if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) - { - crc >>= Chunk_Bits; - crc ^= table[index]; - } - else - { - crc = table[index]; - } - - return crc; - } - else - { - // Extract the most significant nibble of the crc and xor with the value nibble - uint8_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; - - // special case for when chunk size is same as accumulator size. - if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) - { - crc <<= Chunk_Bits; - crc ^= table[index]; - } - else - { - crc = table[index]; - } - - return crc; - } - } - - //************************************************************************* - accumulator_type add(accumulator_type crc, uint8_t value) const - { - static ETL_CONSTANT accumulator_type table[Table_Size] = - { - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value - }; - - if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) - { - crc = update_chunk(crc, value & Chunk_Mask, table); - crc = update_chunk(crc, value >> Chunk_Bits, table); - } - else - { - crc = update_chunk(crc, value >> Chunk_Bits, table); - crc = update_chunk(crc, value & Chunk_Mask, table); - } - - return crc; + return TCrcParameters::Reflect ? etl::reverse_bits_const::value + : TCrcParameters::Initial; } //************************************************************************* @@ -592,91 +637,22 @@ namespace etl //********************************* // Policy for 4 entry table. template - struct crc_policy + struct crc_policy : public crc_table { typedef typename TCrcParameters::accumulator_type accumulator_type; typedef accumulator_type value_type; - static ETL_CONSTANT size_t Table_Size = 4U; - static ETL_CONSTANT uint8_t Chunk_Mask = Table_Size - 1U; - static ETL_CONSTANT size_t Chunk_Bits = 2U; - static ETL_CONSTANT size_t Accumulator_Bits = TCrcParameters::Accumulator_Bits; - //************************************************************************* ETL_CONSTEXPR accumulator_type initial() const { - return TCrcParameters::Initial; - } - - //************************************************************************* - static accumulator_type update_chunk(accumulator_type crc, uint8_t value, const accumulator_type table[]) - { - value &= Chunk_Mask; - - if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) - { - uint8_t index = (crc & Chunk_Mask) ^ value; - - // special case for when chunk size is same as accumulator size. - if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) - { - crc >>= Chunk_Bits; - crc ^= table[index]; - } - else - { - crc = table[index]; - } - - return crc; - } - else - { - // Extract the most significant nibble of the crc and xor with the value nibble - uint8_t index = (crc >> (Accumulator_Bits - Chunk_Bits)) ^ value; - - // special case for when chunk size is same as accumulator size. - if ETL_IF_CONSTEXPR(Accumulator_Bits > Chunk_Bits) - { - crc <<= Chunk_Bits; - crc ^= table[index]; - } - else - { - crc = table[index]; - } - - return crc; - } - } - - //************************************************************************* - accumulator_type add(accumulator_type crc, uint8_t value) const - { - static ETL_CONSTANT accumulator_type table[Table_Size] = - { - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value, - crc_table_entry::value - }; - - if ETL_IF_CONSTEXPR(TCrcParameters::Reflect) - { - crc = update_chunk(crc, value & Chunk_Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Bits * 1U)) & Chunk_Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Bits * 2U)) & Chunk_Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Bits * 3U)) & Chunk_Mask, table); - } - else - { - crc = update_chunk(crc, (value >> (Chunk_Bits * 3U)) & Chunk_Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Bits * 2U)) & Chunk_Mask, table); - crc = update_chunk(crc, (value >> (Chunk_Bits * 1U)) & Chunk_Mask, table); - crc = update_chunk(crc, value & Chunk_Mask, table); - } - - return crc; + return TCrcParameters::Reflect ? etl::reverse_bits_const::value + : TCrcParameters::Initial; } //************************************************************************* diff --git a/include/etl/private/crc_parameters.h b/include/etl/private/crc_parameters.h index b90ba3de..343fd1d8 100644 --- a/include/etl/private/crc_parameters.h +++ b/include/etl/private/crc_parameters.h @@ -52,39 +52,40 @@ namespace etl // 8 bit. typedef crc_parameters crc8_ccitt_parameters; typedef crc_parameters crc8_rohc_parameters; - typedef crc_parameters crc8_cdma2000; - typedef crc_parameters crc8_darc; - typedef crc_parameters crc8_dvbs2; - typedef crc_parameters crc8_ebu; - typedef crc_parameters crc8_icode; - typedef crc_parameters crc8_itu; - typedef crc_parameters crc8_maxim; - typedef crc_parameters crc8_wcdma; + typedef crc_parameters crc8_cdma2000_parameters; + typedef crc_parameters crc8_darc_parameters; + typedef crc_parameters crc8_dvbs2_parameters; + typedef crc_parameters crc8_ebu_parameters; + typedef crc_parameters crc8_icode_parameters; + typedef crc_parameters crc8_itu_parameters; + typedef crc_parameters crc8_maxim_parameters; + typedef crc_parameters crc8_wcdma_parameters; // 16 bit. typedef crc_parameters crc16_parameters; typedef crc_parameters crc16_ccitt_parameters; typedef crc_parameters crc16_aug_ccitt_parameters; + typedef crc_parameters crc16_buypass_parameters; typedef crc_parameters crc16_genibus_parameters; + typedef crc_parameters crc16_profibus_parameters; typedef crc_parameters crc16_kermit_parameters; typedef crc_parameters crc16_modbus_parameters; typedef crc_parameters crc16_usb_parameters; typedef crc_parameters crc16_x25_parameters; typedef crc_parameters crc16_xmodem_parameters; - typedef crc_parameters crc16_buypass; - typedef crc_parameters crc16_cdma2000; - typedef crc_parameters crc16_dds110; - typedef crc_parameters crc16_dectr; - typedef crc_parameters crc16_dectx; - typedef crc_parameters crc16_dnp; - typedef crc_parameters crc16_en13757; - typedef crc_parameters crc16_maxim; - typedef crc_parameters crc16_mcrf4xx; - typedef crc_parameters crc16_riello; - typedef crc_parameters crc16_t10dif; - typedef crc_parameters crc16_teledisk; - typedef crc_parameters crc16_tms37157; - typedef crc_parameters crc16_a; + typedef crc_parameters crc16_cdma2000_parameters; + typedef crc_parameters crc16_dds110_parameters; + typedef crc_parameters crc16_dect_r_parameters; + typedef crc_parameters crc16_dect_x_parameters; + typedef crc_parameters crc16_dnp_parameters; + typedef crc_parameters crc16_en13757_parameters; + typedef crc_parameters crc16_maxim_parameters; + typedef crc_parameters crc16_mcrf4xx_parameters; + typedef crc_parameters crc16_riello_parameters; + typedef crc_parameters crc16_t10dif_parameters; + typedef crc_parameters crc16_teledisk_parameters; + typedef crc_parameters crc16_tms37157_parameters; + typedef crc_parameters crc16_a_parameters; // 32 bit. typedef crc_parameters crc32_parameters; @@ -92,10 +93,10 @@ namespace etl typedef crc_parameters crc32_bzip2_parameters; typedef crc_parameters crc32_mpeg2_parameters; typedef crc_parameters crc32_posix_parameters; - typedef crc_parameters crc32_d; - typedef crc_parameters crc32_q; - typedef crc_parameters crc32_jamcrc; - typedef crc_parameters crc32_xfer; + typedef crc_parameters crc32_d_parameters; + typedef crc_parameters crc32_q_parameters; + typedef crc_parameters crc32_jamcrc_parameters; + typedef crc_parameters crc32_xfer_parameters; // 64 bit. typedef crc_parameters crc64_ecma_parameters; diff --git a/test/test_crc16.cpp b/test/test_crc16.cpp new file mode 100644 index 00000000..5126395d --- /dev/null +++ b/test/test_crc16.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16(data.begin(), data.end()); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_add_values) + { + std::string data("123456789"); + + etl::crc16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range) + { + std::string data("123456789"); + + etl::crc16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_16_add_values) + { + std::string data("123456789"); + + etl::crc16_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_16_add_range) + { + std::string data("123456789"); + + etl::crc16_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_4_add_values) + { + std::string data("123456789"); + + etl::crc16_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_4_add_range) + { + std::string data("123456789"); + + etl::crc16_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_a.cpp b/test/test_crc16_a.cpp new file mode 100644 index 00000000..39afc9dc --- /dev/null +++ b/test/test_crc16_a.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_a.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_a) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_a) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_a(data.begin(), data.end()); + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_add_values) + { + std::string data("123456789"); + + etl::crc16_a crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_add_range) + { + std::string data("123456789"); + + etl::crc16_a crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_a crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_a(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_a((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_a(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_a_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_a_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_16_add_values) + { + std::string data("123456789"); + + etl::crc16_a_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_16_add_range) + { + std::string data("123456789"); + + etl::crc16_a_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_a_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_a_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_a_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_a_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_a_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_a_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_4_add_values) + { + std::string data("123456789"); + + etl::crc16_a_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_4_add_range) + { + std::string data("123456789"); + + etl::crc16_a_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_a_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBF05U, crc); + } + + //************************************************************************* + TEST(test_crc16_a_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_a_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_a_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_a_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_aug_ccitt.cpp b/test/test_crc16_aug_ccitt.cpp new file mode 100644 index 00000000..e78b7662 --- /dev/null +++ b/test/test_crc16_aug_ccitt.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_aug_ccitt.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_aug_ccitt) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_aug_ccitt) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_aug_ccitt_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_aug_ccitt_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_16_add_values) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_16_add_range) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_aug_ccitt_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_aug_ccitt_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_aug_ccitt_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_aug_ccitt_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_aug_ccitt_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_4_add_values) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_4_add_range) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_aug_ccitt_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE5CCU, crc); + } + + //************************************************************************* + TEST(test_crc16_aug_ccitt_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_aug_ccitt_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_aug_ccitt_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_aug_ccitt_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_buypass.cpp b/test/test_crc16_buypass.cpp new file mode 100644 index 00000000..2197af65 --- /dev/null +++ b/test/test_crc16_buypass.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_buypass.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_buypass) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_buypass) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_buypass(data.begin(), data.end()); + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_add_values) + { + std::string data("123456789"); + + etl::crc16_buypass crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_add_range) + { + std::string data("123456789"); + + etl::crc16_buypass crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_buypass crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_buypass(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_buypass((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_buypass(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_buypass_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_buypass_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_16_add_values) + { + std::string data("123456789"); + + etl::crc16_buypass_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_16_add_range) + { + std::string data("123456789"); + + etl::crc16_buypass_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_buypass_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_buypass_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_buypass_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_buypass_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_buypass_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_buypass_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_4_add_values) + { + std::string data("123456789"); + + etl::crc16_buypass_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_4_add_range) + { + std::string data("123456789"); + + etl::crc16_buypass_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_buypass_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFEE8U, crc); + } + + //************************************************************************* + TEST(test_crc16_buypass_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_buypass_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_buypass_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_buypass_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_ccitt.cpp b/test/test_crc16_ccitt.cpp new file mode 100644 index 00000000..c2d93655 --- /dev/null +++ b/test/test_crc16_ccitt.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_ccitt.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_ccitt) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_ccitt) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_values) + { + std::string data("123456789"); + + etl::crc16_ccitt crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range) + { + std::string data("123456789"); + + etl::crc16_ccitt crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_ccitt crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_ccitt_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_ccitt_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_16_add_values) + { + std::string data("123456789"); + + etl::crc16_ccitt_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_16_add_range) + { + std::string data("123456789"); + + etl::crc16_ccitt_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_ccitt_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_ccitt_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_ccitt_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_ccitt_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_ccitt_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_ccitt_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_4_add_values) + { + std::string data("123456789"); + + etl::crc16_ccitt_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_4_add_range) + { + std::string data("123456789"); + + etl::crc16_ccitt_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_ccitt_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x29B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_ccitt_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_ccitt_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_ccitt_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_ccitt_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_cdma2000.cpp b/test/test_crc16_cdma2000.cpp new file mode 100644 index 00000000..59e98766 --- /dev/null +++ b/test/test_crc16_cdma2000.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_cdma2000.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_cdma2000) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_cdma2000) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_cdma2000(data.begin(), data.end()); + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_add_values) + { + std::string data("123456789"); + + etl::crc16_cdma2000 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_add_range) + { + std::string data("123456789"); + + etl::crc16_cdma2000 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_cdma2000 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_cdma2000(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_cdma2000((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_cdma2000(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_cdma2000_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_cdma2000_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_16_add_values) + { + std::string data("123456789"); + + etl::crc16_cdma2000_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_16_add_range) + { + std::string data("123456789"); + + etl::crc16_cdma2000_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_cdma2000_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_cdma2000_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_cdma2000_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_cdma2000_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_cdma2000_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_cdma2000_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_4_add_values) + { + std::string data("123456789"); + + etl::crc16_cdma2000_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_4_add_range) + { + std::string data("123456789"); + + etl::crc16_cdma2000_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_cdma2000_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4C06U, crc); + } + + //************************************************************************* + TEST(test_crc16_cdma2000_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_cdma2000_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_cdma2000_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_cdma2000_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_dds110.cpp b/test/test_crc16_dds110.cpp new file mode 100644 index 00000000..ef234ca8 --- /dev/null +++ b/test/test_crc16_dds110.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_dds110.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_dds110) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_dds110) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dds110(data.begin(), data.end()); + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_add_values) + { + std::string data("123456789"); + + etl::crc16_dds110 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_add_range) + { + std::string data("123456789"); + + etl::crc16_dds110 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dds110 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dds110(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dds110((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dds110(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_dds110_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dds110_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_16_add_values) + { + std::string data("123456789"); + + etl::crc16_dds110_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_16_add_range) + { + std::string data("123456789"); + + etl::crc16_dds110_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dds110_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dds110_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dds110_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dds110_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_dds110_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dds110_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_4_add_values) + { + std::string data("123456789"); + + etl::crc16_dds110_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_4_add_range) + { + std::string data("123456789"); + + etl::crc16_dds110_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dds110_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x9ECFU, crc); + } + + //************************************************************************* + TEST(test_crc16_dds110_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dds110_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dds110_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dds110_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_dect_r.cpp b/test/test_crc16_dect_r.cpp new file mode 100644 index 00000000..407dadce --- /dev/null +++ b/test/test_crc16_dect_r.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_dect_r.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_dect_r) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_dect_r) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dect_r(data.begin(), data.end()); + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_add_values) + { + std::string data("123456789"); + + etl::crc16_dect_r crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_add_range) + { + std::string data("123456789"); + + etl::crc16_dect_r crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dect_r crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dect_r(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dect_r((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dect_r(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_dect_r_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dect_r_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_16_add_values) + { + std::string data("123456789"); + + etl::crc16_dect_r_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_16_add_range) + { + std::string data("123456789"); + + etl::crc16_dect_r_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dect_r_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dect_r_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dect_r_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dect_r_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_dect_r_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dect_r_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_4_add_values) + { + std::string data("123456789"); + + etl::crc16_dect_r_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_4_add_range) + { + std::string data("123456789"); + + etl::crc16_dect_r_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dect_r_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007EU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_r_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dect_r_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dect_r_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dect_r_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_dect_x.cpp b/test/test_crc16_dect_x.cpp new file mode 100644 index 00000000..23e04e2c --- /dev/null +++ b/test/test_crc16_dect_x.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_dect_x.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_dect_x) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_dect_x) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dect_x(data.begin(), data.end()); + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_add_values) + { + std::string data("123456789"); + + etl::crc16_dect_x crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_add_range) + { + std::string data("123456789"); + + etl::crc16_dect_x crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dect_x crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dect_x(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dect_x((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dect_x(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_dect_x_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dect_x_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_16_add_values) + { + std::string data("123456789"); + + etl::crc16_dect_x_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_16_add_range) + { + std::string data("123456789"); + + etl::crc16_dect_x_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dect_x_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dect_x_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dect_x_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dect_x_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_dect_x_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dect_x_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_4_add_values) + { + std::string data("123456789"); + + etl::crc16_dect_x_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_4_add_range) + { + std::string data("123456789"); + + etl::crc16_dect_x_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dect_x_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x007FU, crc); + } + + //************************************************************************* + TEST(test_crc16_dect_x_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dect_x_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dect_x_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dect_x_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_dnp.cpp b/test/test_crc16_dnp.cpp new file mode 100644 index 00000000..d138210f --- /dev/null +++ b/test/test_crc16_dnp.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_dnp.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_dnp) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_dnp) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dnp(data.begin(), data.end()); + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_add_values) + { + std::string data("123456789"); + + etl::crc16_dnp crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_add_range) + { + std::string data("123456789"); + + etl::crc16_dnp crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dnp crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dnp(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dnp((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dnp(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_dnp_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dnp_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_16_add_values) + { + std::string data("123456789"); + + etl::crc16_dnp_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_16_add_range) + { + std::string data("123456789"); + + etl::crc16_dnp_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dnp_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dnp_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dnp_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dnp_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_dnp_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_dnp_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_4_add_values) + { + std::string data("123456789"); + + etl::crc16_dnp_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_4_add_range) + { + std::string data("123456789"); + + etl::crc16_dnp_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_dnp_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xEA82U, crc); + } + + //************************************************************************* + TEST(test_crc16_dnp_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_dnp_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_dnp_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_dnp_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_en13757.cpp b/test/test_crc16_en13757.cpp new file mode 100644 index 00000000..97cba0b5 --- /dev/null +++ b/test/test_crc16_en13757.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_en13757.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_en13757) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_en13757) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_en13757(data.begin(), data.end()); + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_add_values) + { + std::string data("123456789"); + + etl::crc16_en13757 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_add_range) + { + std::string data("123456789"); + + etl::crc16_en13757 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_en13757 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_en13757(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_en13757((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_en13757(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_en13757_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_en13757_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_16_add_values) + { + std::string data("123456789"); + + etl::crc16_en13757_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_16_add_range) + { + std::string data("123456789"); + + etl::crc16_en13757_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_en13757_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_en13757_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_en13757_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_en13757_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_en13757_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_en13757_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_4_add_values) + { + std::string data("123456789"); + + etl::crc16_en13757_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_4_add_range) + { + std::string data("123456789"); + + etl::crc16_en13757_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_en13757_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xC2B7U, crc); + } + + //************************************************************************* + TEST(test_crc16_en13757_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_en13757_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_en13757_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_en13757_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_genibus.cpp b/test/test_crc16_genibus.cpp new file mode 100644 index 00000000..14965c27 --- /dev/null +++ b/test/test_crc16_genibus.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_genibus.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_genibus) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_genibus) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_values) + { + std::string data("123456789"); + + etl::crc16_genibus crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range) + { + std::string data("123456789"); + + etl::crc16_genibus crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_genibus crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_genibus_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_genibus_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_16_add_values) + { + std::string data("123456789"); + + etl::crc16_genibus_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_16_add_range) + { + std::string data("123456789"); + + etl::crc16_genibus_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_genibus_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_genibus_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_genibus_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_genibus_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_genibus_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_genibus_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_4_add_values) + { + std::string data("123456789"); + + etl::crc16_genibus_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_4_add_range) + { + std::string data("123456789"); + + etl::crc16_genibus_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_genibus_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD64EU, crc); + } + + //************************************************************************* + TEST(test_crc16_genibus_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_genibus_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_genibus_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_genibus_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_kermit.cpp b/test/test_crc16_kermit.cpp new file mode 100644 index 00000000..dea6cdfd --- /dev/null +++ b/test/test_crc16_kermit.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_kermit.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_kermit) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_kermit) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_values) + { + std::string data("123456789"); + + etl::crc16_kermit crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range) + { + std::string data("123456789"); + + etl::crc16_kermit crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_kermit crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_kermit_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_kermit_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_16_add_values) + { + std::string data("123456789"); + + etl::crc16_kermit_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_16_add_range) + { + std::string data("123456789"); + + etl::crc16_kermit_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_kermit_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_kermit_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_kermit_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_kermit_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_kermit_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_kermit_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_4_add_values) + { + std::string data("123456789"); + + etl::crc16_kermit_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_4_add_range) + { + std::string data("123456789"); + + etl::crc16_kermit_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_kermit_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x2189U, crc); + } + + //************************************************************************* + TEST(test_crc16_kermit_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_kermit_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_kermit_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_kermit_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_maxim.cpp b/test/test_crc16_maxim.cpp new file mode 100644 index 00000000..3a4b4f0f --- /dev/null +++ b/test/test_crc16_maxim.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_maxim.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_maxim) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_maxim) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_maxim(data.begin(), data.end()); + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_add_values) + { + std::string data("123456789"); + + etl::crc16_maxim crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_add_range) + { + std::string data("123456789"); + + etl::crc16_maxim crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_maxim crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_maxim(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_maxim((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_maxim(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_maxim_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_maxim_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_16_add_values) + { + std::string data("123456789"); + + etl::crc16_maxim_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_16_add_range) + { + std::string data("123456789"); + + etl::crc16_maxim_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_maxim_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_maxim_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_maxim_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_maxim_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_maxim_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_maxim_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_4_add_values) + { + std::string data("123456789"); + + etl::crc16_maxim_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_4_add_range) + { + std::string data("123456789"); + + etl::crc16_maxim_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_maxim_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x44C2U, crc); + } + + //************************************************************************* + TEST(test_crc16_maxim_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_maxim_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_maxim_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_maxim_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_mcrf4xx.cpp b/test/test_crc16_mcrf4xx.cpp new file mode 100644 index 00000000..8322a29a --- /dev/null +++ b/test/test_crc16_mcrf4xx.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_mcrf4xx.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_mcrf4xx) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_mcrf4xx) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_mcrf4xx(data.begin(), data.end()); + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_add_values) + { + std::string data("123456789"); + + etl::crc16_mcrf4xx crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_add_range) + { + std::string data("123456789"); + + etl::crc16_mcrf4xx crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_mcrf4xx crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_mcrf4xx(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_mcrf4xx((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_mcrf4xx(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_mcrf4xx_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_mcrf4xx_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_16_add_values) + { + std::string data("123456789"); + + etl::crc16_mcrf4xx_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_16_add_range) + { + std::string data("123456789"); + + etl::crc16_mcrf4xx_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_mcrf4xx_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_mcrf4xx_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_mcrf4xx_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_mcrf4xx_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_mcrf4xx_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_mcrf4xx_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_4_add_values) + { + std::string data("123456789"); + + etl::crc16_mcrf4xx_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_4_add_range) + { + std::string data("123456789"); + + etl::crc16_mcrf4xx_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_mcrf4xx_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6F91U, crc); + } + + //************************************************************************* + TEST(test_crc16_mcrf4xx_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_mcrf4xx_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_mcrf4xx_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_mcrf4xx_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_modbus.cpp b/test/test_crc16_modbus.cpp new file mode 100644 index 00000000..723889e2 --- /dev/null +++ b/test/test_crc16_modbus.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_modbus.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_modbus) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_modbus) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_values) + { + std::string data("123456789"); + + etl::crc16_modbus crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range) + { + std::string data("123456789"); + + etl::crc16_modbus crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_modbus crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_modbus_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_modbus_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_16_add_values) + { + std::string data("123456789"); + + etl::crc16_modbus_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_16_add_range) + { + std::string data("123456789"); + + etl::crc16_modbus_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_modbus_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_modbus_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_modbus_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_modbus_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_modbus_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_modbus_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_4_add_values) + { + std::string data("123456789"); + + etl::crc16_modbus_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_4_add_range) + { + std::string data("123456789"); + + etl::crc16_modbus_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_modbus_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4B37U, crc); + } + + //************************************************************************* + TEST(test_crc16_modbus_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_modbus_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_modbus_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_modbus_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_profibus.cpp b/test/test_crc16_profibus.cpp new file mode 100644 index 00000000..93018a41 --- /dev/null +++ b/test/test_crc16_profibus.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_profibus.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_profibus) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_profibus) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_profibus(data.begin(), data.end()); + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_add_values) + { + std::string data("123456789"); + + etl::crc16_profibus crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_add_range) + { + std::string data("123456789"); + + etl::crc16_profibus crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_profibus crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_profibus(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_profibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_profibus(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_profibus_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_profibus_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_16_add_values) + { + std::string data("123456789"); + + etl::crc16_profibus_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_16_add_range) + { + std::string data("123456789"); + + etl::crc16_profibus_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_profibus_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_profibus_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_profibus_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_profibus_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_profibus_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_profibus_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_4_add_values) + { + std::string data("123456789"); + + etl::crc16_profibus_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_4_add_range) + { + std::string data("123456789"); + + etl::crc16_profibus_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_profibus_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA819U, crc); + } + + //************************************************************************* + TEST(test_crc16_profibus_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_profibus_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_profibus_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_profibus_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_riello.cpp b/test/test_crc16_riello.cpp new file mode 100644 index 00000000..0daf1b89 --- /dev/null +++ b/test/test_crc16_riello.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_riello.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_riello) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_riello) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_riello(data.begin(), data.end()); + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_add_values) + { + std::string data("123456789"); + + etl::crc16_riello crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_add_range) + { + std::string data("123456789"); + + etl::crc16_riello crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_riello crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_riello(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_riello((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_riello(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_riello_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_riello_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_16_add_values) + { + std::string data("123456789"); + + etl::crc16_riello_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_16_add_range) + { + std::string data("123456789"); + + etl::crc16_riello_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_riello_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_riello_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_riello_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_riello_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_riello_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_riello_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_4_add_values) + { + std::string data("123456789"); + + etl::crc16_riello_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_4_add_range) + { + std::string data("123456789"); + + etl::crc16_riello_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_riello_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x63D0U, crc); + } + + //************************************************************************* + TEST(test_crc16_riello_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_riello_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_riello_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_riello_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_t10dif.cpp b/test/test_crc16_t10dif.cpp new file mode 100644 index 00000000..18b8bd59 --- /dev/null +++ b/test/test_crc16_t10dif.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_t10dif.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_t10dif) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_t10dif) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_t10dif(data.begin(), data.end()); + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_add_values) + { + std::string data("123456789"); + + etl::crc16_t10dif crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_add_range) + { + std::string data("123456789"); + + etl::crc16_t10dif crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_t10dif crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_t10dif(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_t10dif((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_t10dif(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_t10dif_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_t10dif_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_16_add_values) + { + std::string data("123456789"); + + etl::crc16_t10dif_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_16_add_range) + { + std::string data("123456789"); + + etl::crc16_t10dif_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_t10dif_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_t10dif_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_t10dif_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_t10dif_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_t10dif_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_t10dif_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_4_add_values) + { + std::string data("123456789"); + + etl::crc16_t10dif_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_4_add_range) + { + std::string data("123456789"); + + etl::crc16_t10dif_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_t10dif_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0DB, crc); + } + + //************************************************************************* + TEST(test_crc16_t10dif_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_t10dif_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_t10dif_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_t10dif_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_teledisk.cpp b/test/test_crc16_teledisk.cpp new file mode 100644 index 00000000..a0adb5fc --- /dev/null +++ b/test/test_crc16_teledisk.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_teledisk.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_teledisk) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_teledisk) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_teledisk(data.begin(), data.end()); + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_add_values) + { + std::string data("123456789"); + + etl::crc16_teledisk crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_add_range) + { + std::string data("123456789"); + + etl::crc16_teledisk crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_teledisk crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_teledisk(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_teledisk((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_teledisk(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_teledisk_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_teledisk_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_16_add_values) + { + std::string data("123456789"); + + etl::crc16_teledisk_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_16_add_range) + { + std::string data("123456789"); + + etl::crc16_teledisk_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_teledisk_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_teledisk_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_teledisk_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_teledisk_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_teledisk_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_teledisk_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_4_add_values) + { + std::string data("123456789"); + + etl::crc16_teledisk_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_4_add_range) + { + std::string data("123456789"); + + etl::crc16_teledisk_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_teledisk_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0FB3U, crc); + } + + //************************************************************************* + TEST(test_crc16_teledisk_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_teledisk_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_teledisk_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_teledisk_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_tms37157.cpp b/test/test_crc16_tms37157.cpp new file mode 100644 index 00000000..0beda000 --- /dev/null +++ b/test/test_crc16_tms37157.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_tms37157.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_tms37157) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_tms37157) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_tms37157(data.begin(), data.end()); + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_add_values) + { + std::string data("123456789"); + + etl::crc16_tms37157 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_add_range) + { + std::string data("123456789"); + + etl::crc16_tms37157 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_tms37157 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_tms37157(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_tms37157((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_tms37157(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_tms37157_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_tms37157_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_16_add_values) + { + std::string data("123456789"); + + etl::crc16_tms37157_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_16_add_range) + { + std::string data("123456789"); + + etl::crc16_tms37157_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_tms37157_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_tms37157_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_tms37157_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_tms37157_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_tms37157_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_tms37157_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_4_add_values) + { + std::string data("123456789"); + + etl::crc16_tms37157_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_4_add_range) + { + std::string data("123456789"); + + etl::crc16_tms37157_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_tms37157_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x26B1U, crc); + } + + //************************************************************************* + TEST(test_crc16_tms37157_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_tms37157_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_tms37157_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_tms37157_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_usb.cpp b/test/test_crc16_usb.cpp new file mode 100644 index 00000000..a36595b9 --- /dev/null +++ b/test/test_crc16_usb.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_usb.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_usb) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_usb) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_usb(data.begin(), data.end()); + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_values) + { + std::string data("123456789"); + + etl::crc16_usb crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range) + { + std::string data("123456789"); + + etl::crc16_usb crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_usb crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_usb_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_usb_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_16_add_values) + { + std::string data("123456789"); + + etl::crc16_usb_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_16_add_range) + { + std::string data("123456789"); + + etl::crc16_usb_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_usb_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_usb_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_usb_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_usb_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_usb_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_usb_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_4_add_values) + { + std::string data("123456789"); + + etl::crc16_usb_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_4_add_range) + { + std::string data("123456789"); + + etl::crc16_usb_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_usb_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xB4C8U, crc); + } + + //************************************************************************* + TEST(test_crc16_usb_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_usb_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_usb_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_usb_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_x25.cpp b/test/test_crc16_x25.cpp new file mode 100644 index 00000000..cc898657 --- /dev/null +++ b/test/test_crc16_x25.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_x25.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_x25) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_x25) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_x25(data.begin(), data.end()); + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_values) + { + std::string data("123456789"); + + etl::crc16_x25 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range) + { + std::string data("123456789"); + + etl::crc16_x25 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_x25 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_x25_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_x25_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_16_add_values) + { + std::string data("123456789"); + + etl::crc16_x25_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_16_add_range) + { + std::string data("123456789"); + + etl::crc16_x25_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_x25_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_x25_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_x25_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_x25_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_x25_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_x25_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_4_add_values) + { + std::string data("123456789"); + + etl::crc16_x25_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_4_add_range) + { + std::string data("123456789"); + + etl::crc16_x25_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_x25_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x906EU, crc); + } + + //************************************************************************* + TEST(test_crc16_x25_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_x25_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_x25_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_x25_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc16_xmodem.cpp b/test/test_crc16_xmodem.cpp new file mode 100644 index 00000000..e45cc6dc --- /dev/null +++ b/test/test_crc16_xmodem.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_xmodem.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_xmodem) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_xmodem) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_values) + { + std::string data("123456789"); + + etl::crc16_xmodem crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range) + { + std::string data("123456789"); + + etl::crc16_xmodem crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_xmodem crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_xmodem_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_xmodem_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_16_add_values) + { + std::string data("123456789"); + + etl::crc16_xmodem_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_16_add_range) + { + std::string data("123456789"); + + etl::crc16_xmodem_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_xmodem_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_xmodem_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_xmodem_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_xmodem_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_xmodem_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_xmodem_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_4_add_values) + { + std::string data("123456789"); + + etl::crc16_xmodem_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_4_add_range) + { + std::string data("123456789"); + + etl::crc16_xmodem_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_xmodem_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x31C3U, crc); + } + + //************************************************************************* + TEST(test_crc16_xmodem_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_xmodem_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_xmodem_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_xmodem_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc32.cpp b/test/test_crc32.cpp new file mode 100644 index 00000000..6a078cdc --- /dev/null +++ b/test/test_crc32.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc32.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc32) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc32) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32(data.begin(), data.end()); + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_add_values) + { + std::string data("123456789"); + + etl::crc32 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range) + { + std::string data("123456789"); + + etl::crc32 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc32_16) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_16_add_values) + { + std::string data("123456789"); + + etl::crc32_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_16_add_range) + { + std::string data("123456789"); + + etl::crc32_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc32_4) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_4_add_values) + { + std::string data("123456789"); + + etl::crc32_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_4_add_range) + { + std::string data("123456789"); + + etl::crc32_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xCBF43926U, crc); + } + + //************************************************************************* + TEST(test_crc32_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc32_bzip2.cpp b/test/test_crc32_bzip2.cpp new file mode 100644 index 00000000..d92a686e --- /dev/null +++ b/test/test_crc32_bzip2.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc32_bzip2.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc32_bzip2) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc32_bzip2) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_values) + { + std::string data("123456789"); + + etl::crc32_bzip2 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_range) + { + std::string data("123456789"); + + etl::crc32_bzip2 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_bzip2 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc32_bzip2_16) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_bzip2_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_16_add_values) + { + std::string data("123456789"); + + etl::crc32_bzip2_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_16_add_range) + { + std::string data("123456789"); + + etl::crc32_bzip2_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_bzip2_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_bzip2_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_bzip2_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_bzip2_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc32_bzip2_4) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_bzip2_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_4_add_values) + { + std::string data("123456789"); + + etl::crc32_bzip2_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_4_add_range) + { + std::string data("123456789"); + + etl::crc32_bzip2_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_bzip2_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xFC891918U, crc); + } + + //************************************************************************* + TEST(test_crc32_bzip2_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_bzip2_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_bzip2_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_bzip2_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc32_c.cpp b/test/test_crc32_c.cpp new file mode 100644 index 00000000..7c9b585b --- /dev/null +++ b/test/test_crc32_c.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc32_c.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc32_c) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc32_c) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_c(data.begin(), data.end()); + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_values) + { + std::string data("123456789"); + + etl::crc32_c crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_range) + { + std::string data("123456789"); + + etl::crc32_c crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_c crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc32_c_16) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_c_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_16_add_values) + { + std::string data("123456789"); + + etl::crc32_c_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_16_add_range) + { + std::string data("123456789"); + + etl::crc32_c_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_c_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_c_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_c_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_c_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc32_c_4) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_c_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_4_add_values) + { + std::string data("123456789"); + + etl::crc32_c_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_4_add_range) + { + std::string data("123456789"); + + etl::crc32_c_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_c_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xE3069283U, crc); + } + + //************************************************************************* + TEST(test_crc32_c_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_c_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_c_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_c_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc32_d.cpp b/test/test_crc32_d.cpp new file mode 100644 index 00000000..cefc7455 --- /dev/null +++ b/test/test_crc32_d.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc32_d.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc32_d) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc32_d) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_d(data.begin(), data.end()); + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_add_values) + { + std::string data("123456789"); + + etl::crc32_d crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_add_range) + { + std::string data("123456789"); + + etl::crc32_d crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_d crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_d(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_d((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_d(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc32_d_16) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_d_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_16_add_values) + { + std::string data("123456789"); + + etl::crc32_d_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_16_add_range) + { + std::string data("123456789"); + + etl::crc32_d_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_d_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_d_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_d_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_d_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc32_d_4) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_d_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_4_add_values) + { + std::string data("123456789"); + + etl::crc32_d_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_4_add_range) + { + std::string data("123456789"); + + etl::crc32_d_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_d_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x87315576, crc); + } + + //************************************************************************* + TEST(test_crc32_d_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_d_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_d_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_d_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc32_jamcrc.cpp b/test/test_crc32_jamcrc.cpp new file mode 100644 index 00000000..3f71931d --- /dev/null +++ b/test/test_crc32_jamcrc.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc32_jamcrc.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc32_jamcrc) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc32_jamcrc) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_jamcrc(data.begin(), data.end()); + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_add_values) + { + std::string data("123456789"); + + etl::crc32_jamcrc crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_add_range) + { + std::string data("123456789"); + + etl::crc32_jamcrc crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_jamcrc crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_jamcrc(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_jamcrc((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_jamcrc(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc32_jamcrc_16) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_jamcrc_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_16_add_values) + { + std::string data("123456789"); + + etl::crc32_jamcrc_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_16_add_range) + { + std::string data("123456789"); + + etl::crc32_jamcrc_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_jamcrc_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_jamcrc_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_jamcrc_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_jamcrc_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc32_jamcrc_4) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_jamcrc_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_4_add_values) + { + std::string data("123456789"); + + etl::crc32_jamcrc_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_4_add_range) + { + std::string data("123456789"); + + etl::crc32_jamcrc_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_jamcrc_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x340BC6D9, crc); + } + + //************************************************************************* + TEST(test_crc32_jamcrc_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_jamcrc_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_jamcrc_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_jamcrc_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc32_mpeg2.cpp b/test/test_crc32_mpeg2.cpp new file mode 100644 index 00000000..a84bd1d0 --- /dev/null +++ b/test/test_crc32_mpeg2.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc32_mpeg2.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc32_mpeg2) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc32_mpeg2) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_values) + { + std::string data("123456789"); + + etl::crc32_mpeg2 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_range) + { + std::string data("123456789"); + + etl::crc32_mpeg2 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_mpeg2 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc32_mpeg2_16) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_mpeg2_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_16_add_values) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_16_add_range) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_mpeg2_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_mpeg2_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_mpeg2_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc32_mpeg2_4) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_mpeg2_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_4_add_values) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_4_add_range) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_mpeg2_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x0376E6E7U, crc); + } + + //************************************************************************* + TEST(test_crc32_mpeg2_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_mpeg2_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_mpeg2_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_mpeg2_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc32_posix.cpp b/test/test_crc32_posix.cpp new file mode 100644 index 00000000..9c4f41d9 --- /dev/null +++ b/test/test_crc32_posix.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc32_posix.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc32_posix) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc32_posix) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_posix(data.begin(), data.end()); + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_values) + { + std::string data("123456789"); + + etl::crc32_posix crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_range) + { + std::string data("123456789"); + + etl::crc32_posix crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_posix crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc32_posix_16) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_posix_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_16_add_values) + { + std::string data("123456789"); + + etl::crc32_posix_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_16_add_range) + { + std::string data("123456789"); + + etl::crc32_posix_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_posix_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_posix_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_posix_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_posix_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc32_posix_4) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_posix_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_4_add_values) + { + std::string data("123456789"); + + etl::crc32_posix_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_4_add_range) + { + std::string data("123456789"); + + etl::crc32_posix_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_posix_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x765E7680U, crc); + } + + //************************************************************************* + TEST(test_crc32_posix_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_posix_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_posix_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_posix_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc32_q.cpp b/test/test_crc32_q.cpp new file mode 100644 index 00000000..99f751fc --- /dev/null +++ b/test/test_crc32_q.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc32_q.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc32_q) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc32_q) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_q(data.begin(), data.end()); + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_add_values) + { + std::string data("123456789"); + + etl::crc32_q crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_add_range) + { + std::string data("123456789"); + + etl::crc32_q crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_q crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_q(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_q((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_q(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc32_q_16) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_q_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_16_add_values) + { + std::string data("123456789"); + + etl::crc32_q_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_16_add_range) + { + std::string data("123456789"); + + etl::crc32_q_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_q_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_q_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_q_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_q_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc32_q_4) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_q_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_4_add_values) + { + std::string data("123456789"); + + etl::crc32_q_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_4_add_range) + { + std::string data("123456789"); + + etl::crc32_q_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_q_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x3010BF7FU, crc); + } + + //************************************************************************* + TEST(test_crc32_q_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_q_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_q_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_q_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc32_xfer.cpp b/test/test_crc32_xfer.cpp new file mode 100644 index 00000000..f89fe479 --- /dev/null +++ b/test/test_crc32_xfer.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc32_xfer.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc32_xfer) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc32_xfer) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_xfer(data.begin(), data.end()); + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_add_values) + { + std::string data("123456789"); + + etl::crc32_xfer crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_add_range) + { + std::string data("123456789"); + + etl::crc32_xfer crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_xfer crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_xfer(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_xfer((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_xfer(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc32_xfer_16) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_xfer_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_16_add_values) + { + std::string data("123456789"); + + etl::crc32_xfer_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_16_add_range) + { + std::string data("123456789"); + + etl::crc32_xfer_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_xfer_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_xfer_t16(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_xfer_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_xfer_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc32_xfer_4) + { + std::string data("123456789"); + + uint32_t crc = etl::crc32_xfer_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_4_add_values) + { + std::string data("123456789"); + + etl::crc32_xfer_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint32_t crc = crc_calculator; + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_4_add_range) + { + std::string data("123456789"); + + etl::crc32_xfer_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc32_xfer_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint32_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBD0BE338U, crc); + } + + //************************************************************************* + TEST(test_crc32_xfer_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint32_t crc1 = etl::crc32_xfer_t4(data1.begin(), data1.end()); + uint32_t crc2 = etl::crc32_xfer_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint32_t crc3 = etl::crc32_xfer_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc64_ecma.cpp b/test/test_crc64_ecma.cpp new file mode 100644 index 00000000..89b08bcc --- /dev/null +++ b/test/test_crc64_ecma.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc64_ecma.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc64_ecma) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc64_ecma) + { + std::string data("123456789"); + + uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_values) + { + std::string data("123456789"); + + etl::crc64_ecma crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint64_t crc = crc_calculator; + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range) + { + std::string data("123456789"); + + etl::crc64_ecma crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc64_ecma crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); + uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc64_ecma_16) + { + std::string data("123456789"); + + uint64_t crc = etl::crc64_ecma_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_16_add_values) + { + std::string data("123456789"); + + etl::crc64_ecma_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint64_t crc = crc_calculator; + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_16_add_range) + { + std::string data("123456789"); + + etl::crc64_ecma_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc64_ecma_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint64_t crc1 = etl::crc64_ecma_t16(data1.begin(), data1.end()); + uint64_t crc2 = etl::crc64_ecma_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint64_t crc3 = etl::crc64_ecma_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc64_ecma_4) + { + std::string data("123456789"); + + uint64_t crc = etl::crc64_ecma_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_4_add_values) + { + std::string data("123456789"); + + etl::crc64_ecma_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint64_t crc = crc_calculator; + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_4_add_range) + { + std::string data("123456789"); + + etl::crc64_ecma_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc64_ecma_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint64_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x6C40DF5F0B497347U, crc); + } + + //************************************************************************* + TEST(test_crc64_ecma_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint64_t crc1 = etl::crc64_ecma_t4(data1.begin(), data1.end()); + uint64_t crc2 = etl::crc64_ecma_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint64_t crc3 = etl::crc64_ecma_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/test_crc8_ccitt.cpp b/test/test_crc8_ccitt.cpp new file mode 100644 index 00000000..c7456072 --- /dev/null +++ b/test/test_crc8_ccitt.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_ccitt.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_ccitt_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_ccitt_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_4_add_values) + { + std::string data("123456789"); + + etl::crc8_ccitt_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_4_add_range) + { + std::string data("123456789"); + + etl::crc8_ccitt_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_ccitt_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_ccitt_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_ccitt_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_ccitt_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_ccitt_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_ccitt_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_16_add_values) + { + std::string data("123456789"); + + etl::crc8_ccitt_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_16_add_range) + { + std::string data("123456789"); + + etl::crc8_ccitt_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_ccitt_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_ccitt_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_ccitt_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_ccitt_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_ccitt_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_ccitt(data.begin(), data.end()); + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_256_add_values) + { + std::string data("123456789"); + + etl::crc8_ccitt crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_256_add_range) + { + std::string data("123456789"); + + etl::crc8_ccitt crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_ccitt crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xF4U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ccitt_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_ccitt(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_ccitt(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_cdma2000.cpp b/test/test_crc8_cdma2000.cpp new file mode 100644 index 00000000..9b2590bc --- /dev/null +++ b/test/test_crc8_cdma2000.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_cdma2000.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_cdma2000_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_cdma2000_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_4_add_values) + { + std::string data("123456789"); + + etl::crc8_cdma2000_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_4_add_range) + { + std::string data("123456789"); + + etl::crc8_cdma2000_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_cdma2000_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_cdma2000_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_cdma2000_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_cdma2000_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_cdma2000_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_cdma2000_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_16_add_values) + { + std::string data("123456789"); + + etl::crc8_cdma2000_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_16_add_range) + { + std::string data("123456789"); + + etl::crc8_cdma2000_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_cdma2000_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_cdma2000_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_cdma2000_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_cdma2000_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_cdma2000_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_cdma2000(data.begin(), data.end()); + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_256_add_values) + { + std::string data("123456789"); + + etl::crc8_cdma2000 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_256_add_range) + { + std::string data("123456789"); + + etl::crc8_cdma2000 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_cdma2000 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xDAU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_cdma2000_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_cdma2000(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_cdma2000((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_cdma2000(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_darc.cpp b/test/test_crc8_darc.cpp new file mode 100644 index 00000000..54db7e4d --- /dev/null +++ b/test/test_crc8_darc.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_darc.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_darc_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_darc_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_4_add_values) + { + std::string data("123456789"); + + etl::crc8_darc_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_4_add_range) + { + std::string data("123456789"); + + etl::crc8_darc_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_darc_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_darc_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_darc_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_darc_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_darc_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_darc_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_16_add_values) + { + std::string data("123456789"); + + etl::crc8_darc_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_16_add_range) + { + std::string data("123456789"); + + etl::crc8_darc_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_darc_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_darc_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_darc_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_darc_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_darc_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_darc(data.begin(), data.end()); + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_256_add_values) + { + std::string data("123456789"); + + etl::crc8_darc crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_256_add_range) + { + std::string data("123456789"); + + etl::crc8_darc crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_darc crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x15U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_darc_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_darc(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_darc((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_darc(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_dvbs2.cpp b/test/test_crc8_dvbs2.cpp new file mode 100644 index 00000000..ac3271ab --- /dev/null +++ b/test/test_crc8_dvbs2.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_dvbs2.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_dvbs2_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_dvbs2_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_4_add_values) + { + std::string data("123456789"); + + etl::crc8_dvbs2_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_4_add_range) + { + std::string data("123456789"); + + etl::crc8_dvbs2_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_dvbs2_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_dvbs2_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_dvbs2_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_dvbs2_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_dvbs2_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_dvbs2_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_16_add_values) + { + std::string data("123456789"); + + etl::crc8_dvbs2_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_16_add_range) + { + std::string data("123456789"); + + etl::crc8_dvbs2_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_dvbs2_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_dvbs2_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_dvbs2_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_dvbs2_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_dvbs2_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_dvbs2(data.begin(), data.end()); + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_256_add_values) + { + std::string data("123456789"); + + etl::crc8_dvbs2 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_256_add_range) + { + std::string data("123456789"); + + etl::crc8_dvbs2 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_dvbs2 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBCU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_dvbs2_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_dvbs2(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_dvbs2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_dvbs2(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_ebu.cpp b/test/test_crc8_ebu.cpp new file mode 100644 index 00000000..85808149 --- /dev/null +++ b/test/test_crc8_ebu.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_ebu.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_ebu_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_ebu_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_4_add_values) + { + std::string data("123456789"); + + etl::crc8_ebu_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_4_add_range) + { + std::string data("123456789"); + + etl::crc8_ebu_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_ebu_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_ebu_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_ebu_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_ebu_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_ebu_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_ebu_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_16_add_values) + { + std::string data("123456789"); + + etl::crc8_ebu_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_16_add_range) + { + std::string data("123456789"); + + etl::crc8_ebu_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_ebu_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_ebu_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_ebu_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_ebu_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_ebu_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_ebu(data.begin(), data.end()); + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_256_add_values) + { + std::string data("123456789"); + + etl::crc8_ebu crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_256_add_range) + { + std::string data("123456789"); + + etl::crc8_ebu crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_ebu crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x97U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_ebu_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_ebu(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_ebu((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_ebu(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_icode.cpp b/test/test_crc8_icode.cpp new file mode 100644 index 00000000..0097aadd --- /dev/null +++ b/test/test_crc8_icode.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_icode.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_icode_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_icode_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_4_add_values) + { + std::string data("123456789"); + + etl::crc8_icode_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_4_add_range) + { + std::string data("123456789"); + + etl::crc8_icode_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_icode_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_icode_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_icode_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_icode_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_icode_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_icode_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_16_add_values) + { + std::string data("123456789"); + + etl::crc8_icode_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_16_add_range) + { + std::string data("123456789"); + + etl::crc8_icode_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_icode_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_icode_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_icode_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_icode_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_icode_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_icode(data.begin(), data.end()); + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_256_add_values) + { + std::string data("123456789"); + + etl::crc8_icode crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_256_add_range) + { + std::string data("123456789"); + + etl::crc8_icode crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_icode crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x7EU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_icode_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_icode(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_icode((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_icode(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_itu.cpp b/test/test_crc8_itu.cpp new file mode 100644 index 00000000..e53941d1 --- /dev/null +++ b/test/test_crc8_itu.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_itu.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_itu_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_itu_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_4_add_values) + { + std::string data("123456789"); + + etl::crc8_itu_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_4_add_range) + { + std::string data("123456789"); + + etl::crc8_itu_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_itu_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_itu_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_itu_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_itu_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_itu_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_itu_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_16_add_values) + { + std::string data("123456789"); + + etl::crc8_itu_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_16_add_range) + { + std::string data("123456789"); + + etl::crc8_itu_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_itu_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_itu_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_itu_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_itu_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_itu_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_itu(data.begin(), data.end()); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_256_add_values) + { + std::string data("123456789"); + + etl::crc8_itu crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_256_add_range) + { + std::string data("123456789"); + + etl::crc8_itu crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_itu crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_itu_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_itu(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_itu((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_itu(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_maxim.cpp b/test/test_crc8_maxim.cpp new file mode 100644 index 00000000..44e897bd --- /dev/null +++ b/test/test_crc8_maxim.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_maxim.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_maxim_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_maxim_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_4_add_values) + { + std::string data("123456789"); + + etl::crc8_maxim_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_4_add_range) + { + std::string data("123456789"); + + etl::crc8_maxim_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_maxim_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_maxim_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_maxim_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_maxim_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_maxim_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_maxim_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_16_add_values) + { + std::string data("123456789"); + + etl::crc8_maxim_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_16_add_range) + { + std::string data("123456789"); + + etl::crc8_maxim_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_maxim_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_maxim_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_maxim_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_maxim_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_maxim_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_maxim(data.begin(), data.end()); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_256_add_values) + { + std::string data("123456789"); + + etl::crc8_maxim crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_256_add_range) + { + std::string data("123456789"); + + etl::crc8_maxim crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_maxim crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xA1U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_maxim_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_maxim(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_maxim((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_maxim(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_rohc.cpp b/test/test_crc8_rohc.cpp new file mode 100644 index 00000000..2131de67 --- /dev/null +++ b/test/test_crc8_rohc.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_rohc.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_rohc_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_rohc_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_4_add_values) + { + std::string data("123456789"); + + etl::crc8_rohc_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_4_add_range) + { + std::string data("123456789"); + + etl::crc8_rohc_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_rohc_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_rohc_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_rohc_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_rohc_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_rohc_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_rohc_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_16_add_values) + { + std::string data("123456789"); + + etl::crc8_rohc_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_16_add_range) + { + std::string data("123456789"); + + etl::crc8_rohc_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_rohc_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_rohc_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_rohc_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_rohc_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_rohc_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_rohc(data.begin(), data.end()); + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_256_add_values) + { + std::string data("123456789"); + + etl::crc8_rohc crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_256_add_range) + { + std::string data("123456789"); + + etl::crc8_rohc crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_rohc crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xD0U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_rohc_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_rohc(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_rohc((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_rohc(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_wcdma.cpp b/test/test_crc8_wcdma.cpp new file mode 100644 index 00000000..1a12e9bf --- /dev/null +++ b/test/test_crc8_wcdma.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_wcdma.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc_experimental) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_wcdma_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_wcdma_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_4_add_values) + { + std::string data("123456789"); + + etl::crc8_wcdma_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_4_add_range) + { + std::string data("123456789"); + + etl::crc8_wcdma_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_wcdma_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_wcdma_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_wcdma_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_wcdma_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_wcdma_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_wcdma_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_16_add_values) + { + std::string data("123456789"); + + etl::crc8_wcdma_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_16_add_range) + { + std::string data("123456789"); + + etl::crc8_wcdma_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_wcdma_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_wcdma_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_wcdma_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_wcdma_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_wcdma_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_wcdma(data.begin(), data.end()); + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_256_add_values) + { + std::string data("123456789"); + + etl::crc8_wcdma crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_256_add_range) + { + std::string data("123456789"); + + etl::crc8_wcdma crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_wcdma crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x25U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_wcdma_256_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint8_t crc1 = etl::crc8_wcdma(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_wcdma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_wcdma(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc_table16.cpp b/test/test_crc_table16.cpp deleted file mode 100644 index eae752b5..00000000 --- a/test/test_crc_table16.cpp +++ /dev/null @@ -1,1257 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2021 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include "unit_test_framework.h" - -#include -#include -#include -#include - -#include "etl/crc8_ccitt.h" -#include "etl/crc8_rohc.h" -#include "etl/crc16.h" -#include "etl/crc16_aug_ccitt.h" -#include "etl/crc16_ccitt.h" -#include "etl/crc16_kermit.h" -#include "etl/crc16_modbus.h" -#include "etl/crc16_usb.h" -#include "etl/crc16_genibus.h" -#include "etl/crc16_x25.h" -#include "etl/crc16_xmodem.h" -#include "etl/crc32.h" -#include "etl/crc32_c.h" -#include "etl/crc32_bzip2.h" -#include "etl/crc32_mpeg2.h" -#include "etl/crc32_posix.h" -#include "etl/crc64_ecma.h" - -//***************************************************************************** -// The results for these tests were created from https://crccalc.com/ -//***************************************************************************** - -namespace -{ - SUITE(test_crc_t16_experimental) - { - //************************************************************************* - TEST(test_crc8_ccitt_constructor) - { - std::string data("123456789"); - - uint8_t crc = etl::crc8_ccitt_t16(data.begin(), data.end()); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc8_ccitt_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint8_t crc = crc_calculator; - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc8_ccitt_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc8_ccitt_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint8_t crc1 = etl::crc8_ccitt_t16(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc8_ccitt_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(int(crc1), int(crc2)); - - uint8_t crc3 = etl::crc8_ccitt_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(int(crc1), int(crc3)); - } - - //************************************************************************* - TEST(test_crc8_rohc_constructor) - { - std::string data("123456789"); - - uint8_t crc = etl::crc8_rohc_t16(data.begin(), data.end()); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_values) - { - std::string data("123456789"); - - etl::crc8_rohc_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint8_t crc = crc_calculator; - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range) - { - std::string data("123456789"); - - etl::crc8_rohc_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc8_rohc_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint8_t crc1 = etl::crc8_rohc_t16(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc8_rohc_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(int(crc1), int(crc2)); - - uint8_t crc3 = etl::crc8_rohc_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(int(crc1), int(crc3)); - } - - //************************************************************************* - TEST(test_crc16) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_t16(data.begin(), data.end()); - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_values) - { - std::string data("123456789"); - - etl::crc16_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range) - { - std::string data("123456789"); - - etl::crc16_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_t16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_ccitt_t16(data.begin(), data.end()); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc16_ccitt_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc16_ccitt_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_ccitt_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_ccitt_t16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_ccitt_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_ccitt_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_kermit) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_kermit_t16(data.begin(), data.end()); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_values) - { - std::string data("123456789"); - - etl::crc16_kermit_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range) - { - std::string data("123456789"); - - etl::crc16_kermit_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_kermit_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_kermit_t16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_kermit_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_kermit_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_modbus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_modbus_t16(data.begin(), data.end()); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_values) - { - std::string data("123456789"); - - etl::crc16_modbus_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range) - { - std::string data("123456789"); - - etl::crc16_modbus_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_modbus_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_modbus_t16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_modbus_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_modbus_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_usb) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_usb_t16(data.begin(), data.end()); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_values) - { - std::string data("123456789"); - - etl::crc16_usb_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range) - { - std::string data("123456789"); - - etl::crc16_usb_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_usb_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_usb_t16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_usb_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_usb_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_xmodem) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_xmodem_t16(data.begin(), data.end()); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_values) - { - std::string data("123456789"); - - etl::crc16_xmodem_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range) - { - std::string data("123456789"); - - etl::crc16_xmodem_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_xmodem_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_xmodem_t16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_xmodem_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_xmodem_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_aug_ccitt_t16(data.begin(), data.end()); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_aug_ccitt_t16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_aug_ccitt_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_aug_ccitt_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_genibus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_genibus_t16(data.begin(), data.end()); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_values) - { - std::string data("123456789"); - - etl::crc16_genibus_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range) - { - std::string data("123456789"); - - etl::crc16_genibus_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_genibus_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_genibus_t16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_genibus_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_genibus_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_x25) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_x25_t16(data.begin(), data.end()); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_values) - { - std::string data("123456789"); - - etl::crc16_x25_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range) - { - std::string data("123456789"); - - etl::crc16_x25_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_x25_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_x25_t16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_x25_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_x25_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_t16(data.begin(), data.end()); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_values) - { - std::string data("123456789"); - - etl::crc32_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range) - { - std::string data("123456789"); - - etl::crc32_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_t16(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_c) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_c_t16(data.begin(), data.end()); - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_values) - { - std::string data("123456789"); - - etl::crc32_c_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range) - { - std::string data("123456789"); - - etl::crc32_c_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_c_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_c_t16(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_c_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_c_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_bzip2) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_bzip2_t16(data.begin(), data.end()); - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_values) - { - std::string data("123456789"); - - etl::crc32_bzip2_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range) - { - std::string data("123456789"); - - etl::crc32_bzip2_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_bzip2_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_bzip2_t16(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_bzip2_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_bzip2_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_posix) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_posix_t16(data.begin(), data.end()); - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_values) - { - std::string data("123456789"); - - etl::crc32_posix_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range) - { - std::string data("123456789"); - - etl::crc32_posix_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_posix_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_posix_t16(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_posix_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_posix_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_mpeg2) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_mpeg2_t16(data.begin(), data.end()); - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_values) - { - std::string data("123456789"); - - etl::crc32_mpeg2_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range) - { - std::string data("123456789"); - - etl::crc32_mpeg2_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_mpeg2_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_mpeg2_t16(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_mpeg2_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_mpeg2_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc64_ecma) - { - std::string data("123456789"); - - uint64_t crc = etl::crc64_ecma_t16(data.begin(), data.end()); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_values) - { - std::string data("123456789"); - - etl::crc64_ecma_t16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint64_t crc = crc_calculator; - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range) - { - std::string data("123456789"); - - etl::crc64_ecma_t16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc64_ecma_t16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint64_t crc1 = etl::crc64_ecma_t16(data1.begin(), data1.end()); - uint64_t crc2 = etl::crc64_ecma_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint64_t crc3 = etl::crc64_ecma_t16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - }; -} - diff --git a/test/test_crc_table256.cpp b/test/test_crc_table256.cpp deleted file mode 100644 index 20c04dcd..00000000 --- a/test/test_crc_table256.cpp +++ /dev/null @@ -1,1258 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2021 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include "unit_test_framework.h" - -#include -#include -#include -#include - -#include "etl/crc8_ccitt.h" -#include "etl/crc8_rohc.h" -#include "etl/crc16.h" -#include "etl/crc16_aug_ccitt.h" -#include "etl/crc16_ccitt.h" -#include "etl/crc16_kermit.h" -#include "etl/crc16_modbus.h" -#include "etl/crc16_usb.h" -#include "etl/crc16_genibus.h" -#include "etl/crc16_x25.h" -#include "etl/crc16_xmodem.h" -#include "etl/crc32.h" -#include "etl/crc32_c.h" -#include "etl/crc32_bzip2.h" -#include "etl/crc32_mpeg2.h" -#include "etl/crc32_posix.h" -#include "etl/crc64_ecma.h" - -//***************************************************************************** -// The results for these tests were created from https://crccalc.com/ -//***************************************************************************** - -namespace -{ - SUITE(test_crc_experimental) - { - //************************************************************************* - TEST(test_crc8_ccitt_constructor) - { - std::string data("123456789"); - - uint8_t crc = etl::crc8_ccitt(data.begin(), data.end()); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc8_ccitt crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint8_t crc = crc_calculator; - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc8_ccitt crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc8_ccitt crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint8_t crc1 = etl::crc8_ccitt(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc8_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(int(crc1), int(crc2)); - - uint8_t crc3 = etl::crc8_ccitt(data3.rbegin(), data3.rend()); - CHECK_EQUAL(int(crc1), int(crc3)); - } - - //************************************************************************* - TEST(test_crc8_rohc_constructor) - { - std::string data("123456789"); - - uint8_t crc = etl::crc8_rohc(data.begin(), data.end()); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_values) - { - std::string data("123456789"); - - etl::crc8_rohc crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint8_t crc = crc_calculator; - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range) - { - std::string data("123456789"); - - etl::crc8_rohc crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc8_rohc crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint8_t crc1 = etl::crc8_rohc(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc8_rohc((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(int(crc1), int(crc2)); - - uint8_t crc3 = etl::crc8_rohc(data3.rbegin(), data3.rend()); - CHECK_EQUAL(int(crc1), int(crc3)); - } - - //************************************************************************* - TEST(test_crc16) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16(data.begin(), data.end()); - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_values) - { - std::string data("123456789"); - - etl::crc16 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range) - { - std::string data("123456789"); - - etl::crc16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc16_ccitt crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc16_ccitt crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_ccitt crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_kermit) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_values) - { - std::string data("123456789"); - - etl::crc16_kermit crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range) - { - std::string data("123456789"); - - etl::crc16_kermit crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_kermit crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_modbus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_values) - { - std::string data("123456789"); - - etl::crc16_modbus crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range) - { - std::string data("123456789"); - - etl::crc16_modbus crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_modbus crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_usb) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_usb(data.begin(), data.end()); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_values) - { - std::string data("123456789"); - - etl::crc16_usb crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range) - { - std::string data("123456789"); - - etl::crc16_usb crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_usb crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_xmodem) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_values) - { - std::string data("123456789"); - - etl::crc16_xmodem crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range) - { - std::string data("123456789"); - - etl::crc16_xmodem crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_xmodem crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_genibus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_values) - { - std::string data("123456789"); - - etl::crc16_genibus crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range) - { - std::string data("123456789"); - - etl::crc16_genibus crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_genibus crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_x25) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_x25(data.begin(), data.end()); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_values) - { - std::string data("123456789"); - - etl::crc16_x25 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range) - { - std::string data("123456789"); - - etl::crc16_x25 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_x25 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32(data.begin(), data.end()); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_values) - { - std::string data("123456789"); - - etl::crc32 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range) - { - std::string data("123456789"); - - etl::crc32 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_c) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_c(data.begin(), data.end()); - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_values) - { - std::string data("123456789"); - - etl::crc32_c crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range) - { - std::string data("123456789"); - - etl::crc32_c crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_c crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_bzip2) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_values) - { - std::string data("123456789"); - - etl::crc32_bzip2 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range) - { - std::string data("123456789"); - - etl::crc32_bzip2 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_bzip2 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_posix) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_posix(data.begin(), data.end()); - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_values) - { - std::string data("123456789"); - - etl::crc32_posix crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range) - { - std::string data("123456789"); - - etl::crc32_posix crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_posix crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_mpeg2) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_values) - { - std::string data("123456789"); - - etl::crc32_mpeg2 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range) - { - std::string data("123456789"); - - etl::crc32_mpeg2 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_mpeg2 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc64_ecma) - { - std::string data("123456789"); - - uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_values) - { - std::string data("123456789"); - - etl::crc64_ecma crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint64_t crc = crc_calculator; - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range) - { - std::string data("123456789"); - - etl::crc64_ecma crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc64_ecma crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); - uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - }; -} - diff --git a/test/test_crc_table4.cpp b/test/test_crc_table4.cpp deleted file mode 100644 index 1f8de228..00000000 --- a/test/test_crc_table4.cpp +++ /dev/null @@ -1,1257 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2021 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include "unit_test_framework.h" - -#include -#include -#include -#include - -#include "etl/crc8_ccitt.h" -#include "etl/crc8_rohc.h" -#include "etl/crc16.h" -#include "etl/crc16_aug_ccitt.h" -#include "etl/crc16_ccitt.h" -#include "etl/crc16_kermit.h" -#include "etl/crc16_modbus.h" -#include "etl/crc16_usb.h" -#include "etl/crc16_genibus.h" -#include "etl/crc16_x25.h" -#include "etl/crc16_xmodem.h" -#include "etl/crc32.h" -#include "etl/crc32_c.h" -#include "etl/crc32_bzip2.h" -#include "etl/crc32_mpeg2.h" -#include "etl/crc32_posix.h" -#include "etl/crc64_ecma.h" - -//***************************************************************************** -// The results for these tests were created from https://crccalc.com/ -//***************************************************************************** - -namespace -{ - SUITE(test_crc_t4_experimental) - { - //************************************************************************* - TEST(test_crc8_ccitt_constructor) - { - std::string data("123456789"); - - uint8_t crc = etl::crc8_ccitt_t4(data.begin(), data.end()); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc8_ccitt_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint8_t crc = crc_calculator; - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc8_ccitt_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc8_ccitt_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint8_t crc1 = etl::crc8_ccitt_t4(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc8_ccitt_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(int(crc1), int(crc2)); - - uint8_t crc3 = etl::crc8_ccitt_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(int(crc1), int(crc3)); - } - - //************************************************************************* - TEST(test_crc8_rohc_constructor) - { - std::string data("123456789"); - - uint8_t crc = etl::crc8_rohc_t4(data.begin(), data.end()); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_values) - { - std::string data("123456789"); - - etl::crc8_rohc_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint8_t crc = crc_calculator; - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range) - { - std::string data("123456789"); - - etl::crc8_rohc_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc8_rohc_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint8_t crc1 = etl::crc8_rohc_t4(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc8_rohc_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(int(crc1), int(crc2)); - - uint8_t crc3 = etl::crc8_rohc_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(int(crc1), int(crc3)); - } - - //************************************************************************* - TEST(test_crc16) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_t4(data.begin(), data.end()); - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_values) - { - std::string data("123456789"); - - etl::crc16_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range) - { - std::string data("123456789"); - - etl::crc16_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xBB3D, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_t4(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_ccitt_t4(data.begin(), data.end()); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc16_ccitt_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc16_ccitt_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_ccitt_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_ccitt_t4(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_ccitt_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_ccitt_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_kermit) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_kermit_t4(data.begin(), data.end()); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_values) - { - std::string data("123456789"); - - etl::crc16_kermit_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range) - { - std::string data("123456789"); - - etl::crc16_kermit_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_kermit_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_kermit_t4(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_kermit_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_kermit_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_modbus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_modbus_t4(data.begin(), data.end()); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_values) - { - std::string data("123456789"); - - etl::crc16_modbus_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range) - { - std::string data("123456789"); - - etl::crc16_modbus_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_modbus_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_modbus_t4(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_modbus_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_modbus_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_usb) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_usb_t4(data.begin(), data.end()); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_values) - { - std::string data("123456789"); - - etl::crc16_usb_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range) - { - std::string data("123456789"); - - etl::crc16_usb_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_usb_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_usb_t4(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_usb_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_usb_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_xmodem) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_xmodem_t4(data.begin(), data.end()); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_values) - { - std::string data("123456789"); - - etl::crc16_xmodem_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range) - { - std::string data("123456789"); - - etl::crc16_xmodem_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_xmodem_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_xmodem_t4(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_xmodem_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_xmodem_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_aug_ccitt_t4(data.begin(), data.end()); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CC, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_aug_ccitt_t4(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_aug_ccitt_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_aug_ccitt_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_genibus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_genibus_t4(data.begin(), data.end()); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_values) - { - std::string data("123456789"); - - etl::crc16_genibus_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range) - { - std::string data("123456789"); - - etl::crc16_genibus_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_genibus_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64E, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_genibus_t4(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_genibus_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_genibus_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_x25) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_x25_t4(data.begin(), data.end()); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_values) - { - std::string data("123456789"); - - etl::crc16_x25_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range) - { - std::string data("123456789"); - - etl::crc16_x25_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_x25_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906E, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint16_t crc1 = etl::crc16_x25_t4(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_x25_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_x25_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_t4(data.begin(), data.end()); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_values) - { - std::string data("123456789"); - - etl::crc32_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range) - { - std::string data("123456789"); - - etl::crc32_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_t4(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_c) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_c_t4(data.begin(), data.end()); - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_values) - { - std::string data("123456789"); - - etl::crc32_c_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range) - { - std::string data("123456789"); - - etl::crc32_c_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_c_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE3069283, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_c_t4(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_c_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_c_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_bzip2) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_bzip2_t4(data.begin(), data.end()); - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_values) - { - std::string data("123456789"); - - etl::crc32_bzip2_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range) - { - std::string data("123456789"); - - etl::crc32_bzip2_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_bzip2_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xFC891918, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_bzip2_t4(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_bzip2_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_bzip2_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_posix) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_posix_t4(data.begin(), data.end()); - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_values) - { - std::string data("123456789"); - - etl::crc32_posix_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range) - { - std::string data("123456789"); - - etl::crc32_posix_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_posix_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x765E7680, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_posix_t4(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_posix_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_posix_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_mpeg2) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_mpeg2_t4(data.begin(), data.end()); - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_values) - { - std::string data("123456789"); - - etl::crc32_mpeg2_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range) - { - std::string data("123456789"); - - etl::crc32_mpeg2_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_mpeg2_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x0376E6E7, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint32_t crc1 = etl::crc32_mpeg2_t4(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_mpeg2_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_mpeg2_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc64_ecma) - { - std::string data("123456789"); - - uint64_t crc = etl::crc64_ecma_t4(data.begin(), data.end()); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_values) - { - std::string data("123456789"); - - etl::crc64_ecma_t4 crc_calculator; - - for (size_t i = 0; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint64_t crc = crc_calculator; - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range) - { - std::string data("123456789"); - - etl::crc64_ecma_t4 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc64_ecma_t4 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347U, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_endian) - { - std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; - std::vector data2 = { 0x04030201, 0x08070605 }; - std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - - uint64_t crc1 = etl::crc64_ecma_t4(data1.begin(), data1.end()); - uint64_t crc2 = etl::crc64_ecma_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint64_t crc3 = etl::crc64_ecma_t4(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - }; -} - diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 5ce03d1b..9d83ee4a 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1260,21 +1260,36 @@ + + + + + + + + + + + + + + + @@ -3774,13 +3789,50 @@ - - false - - - - false - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 6f9bfe66..413af252 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -972,6 +972,51 @@ ETL\Private + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + @@ -2087,13 +2132,136 @@ Source Files\Sanity Checks - + Source Files - + Source Files - + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + Source Files From d3d0faa2c180501190dfe08eee4f5be266b257ee Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 30 Mar 2021 19:10:48 +0100 Subject: [PATCH 8/8] CRC updates --- include/etl/crc.h | 80 +++++ include/etl/crc16.h | 2 +- include/etl/crc16_a.h | 2 +- include/etl/crc16_x25.h | 2 +- include/etl/crc8_cdma2000.h | 2 +- include/etl/crc8_darc.h | 2 +- include/etl/crc8_dvbs2.h | 2 +- include/etl/crc8_ebu.h | 2 +- include/etl/crc8_icode.h | 2 +- include/etl/crc8_itu.h | 2 +- include/etl/crc8_maxim.h | 2 +- include/etl/crc8_rohc.h | 2 +- include/etl/crc8_wcdma.h | 2 +- include/etl/private/crc_parameters.h | 1 + test/CMakeLists.txt | 46 ++- test/runtests.sh | 37 ++- test/sanity-check/c++03/CMakeLists.txt | 44 ++- test/sanity-check/c++11/CMakeLists.txt | 44 ++- test/sanity-check/c++14/CMakeLists.txt | 45 ++- test/sanity-check/c++17/CMakeLists.txt | 45 ++- test/sanity-check/crc16_a.h.t.cpp | 29 ++ test/sanity-check/crc16_arc.h.t.cpp | 29 ++ test/sanity-check/crc16_buypass.h.t.cpp | 29 ++ test/sanity-check/crc16_cdma2000.h.t.cpp | 29 ++ test/sanity-check/crc16_dds110.h.t.cpp | 29 ++ test/sanity-check/crc16_dect_r.h.t.cpp | 29 ++ test/sanity-check/crc16_dect_x.h.t.cpp | 29 ++ test/sanity-check/crc16_dnp.h.t.cpp | 29 ++ test/sanity-check/crc16_en13757.h.t.cpp | 29 ++ test/sanity-check/crc16_maxim.h.t.cpp | 29 ++ test/sanity-check/crc16_mcrf4xx.h.t.cpp | 29 ++ test/sanity-check/crc16_profibus.h.t.cpp | 29 ++ test/sanity-check/crc16_riello.h.t.cpp | 29 ++ test/sanity-check/crc16_t10dif.h.t.cpp | 29 ++ test/sanity-check/crc16_teledisk.h.t.cpp | 29 ++ test/sanity-check/crc16_tms37157.h.t.cpp | 29 ++ test/sanity-check/crc32_d.h.t.cpp | 29 ++ test/sanity-check/crc32_jamcrc.h.t.cpp | 29 ++ test/sanity-check/crc32_q.h.t.cpp | 29 ++ test/sanity-check/crc32_xfer.h.t.cpp | 29 ++ test/sanity-check/crc8_cdma2000.h.t.cpp | 29 ++ test/sanity-check/crc8_darc.h.t.cpp | 29 ++ test/sanity-check/crc8_dvbs2.h.t.cpp | 29 ++ test/sanity-check/crc8_ebu.h.t.cpp | 29 ++ test/sanity-check/crc8_icode.h.t.cpp | 29 ++ test/sanity-check/crc8_itu.h.t.cpp | 29 ++ test/sanity-check/crc8_maxim.h.t.cpp | 29 ++ test/sanity-check/crc8_wcdma.h.t.cpp | 29 ++ test/test_crc16_arc.cpp | 263 +++++++++++++++++ test/vs2019/etl.vcxproj | 355 +++++++++++++++++++++++ test/vs2019/etl.vcxproj.filters | 129 ++++++++ 51 files changed, 1868 insertions(+), 57 deletions(-) create mode 100644 include/etl/crc.h create mode 100644 test/sanity-check/crc16_a.h.t.cpp create mode 100644 test/sanity-check/crc16_arc.h.t.cpp create mode 100644 test/sanity-check/crc16_buypass.h.t.cpp create mode 100644 test/sanity-check/crc16_cdma2000.h.t.cpp create mode 100644 test/sanity-check/crc16_dds110.h.t.cpp create mode 100644 test/sanity-check/crc16_dect_r.h.t.cpp create mode 100644 test/sanity-check/crc16_dect_x.h.t.cpp create mode 100644 test/sanity-check/crc16_dnp.h.t.cpp create mode 100644 test/sanity-check/crc16_en13757.h.t.cpp create mode 100644 test/sanity-check/crc16_maxim.h.t.cpp create mode 100644 test/sanity-check/crc16_mcrf4xx.h.t.cpp create mode 100644 test/sanity-check/crc16_profibus.h.t.cpp create mode 100644 test/sanity-check/crc16_riello.h.t.cpp create mode 100644 test/sanity-check/crc16_t10dif.h.t.cpp create mode 100644 test/sanity-check/crc16_teledisk.h.t.cpp create mode 100644 test/sanity-check/crc16_tms37157.h.t.cpp create mode 100644 test/sanity-check/crc32_d.h.t.cpp create mode 100644 test/sanity-check/crc32_jamcrc.h.t.cpp create mode 100644 test/sanity-check/crc32_q.h.t.cpp create mode 100644 test/sanity-check/crc32_xfer.h.t.cpp create mode 100644 test/sanity-check/crc8_cdma2000.h.t.cpp create mode 100644 test/sanity-check/crc8_darc.h.t.cpp create mode 100644 test/sanity-check/crc8_dvbs2.h.t.cpp create mode 100644 test/sanity-check/crc8_ebu.h.t.cpp create mode 100644 test/sanity-check/crc8_icode.h.t.cpp create mode 100644 test/sanity-check/crc8_itu.h.t.cpp create mode 100644 test/sanity-check/crc8_maxim.h.t.cpp create mode 100644 test/sanity-check/crc8_wcdma.h.t.cpp create mode 100644 test/test_crc16_arc.cpp diff --git a/include/etl/crc.h b/include/etl/crc.h new file mode 100644 index 00000000..230b18b5 --- /dev/null +++ b/include/etl/crc.h @@ -0,0 +1,80 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CRC_INCLUDED +#define ETL_CRC_INCLUDED + +#include "crc16.h" +#include "crc16_a.h" +#include "crc16_arc.h" +#include "crc16_aug_ccitt.h" +#include "crc16_buypass.h" +#include "crc16_ccitt.h" +#include "crc16_cdma2000.h" +#include "crc16_dds110.h" +#include "crc16_dect_r.h" +#include "crc16_dect_x.h" +#include "crc16_dnp.h" +#include "crc16_en13757.h" +#include "crc16_genibus.h" +#include "crc16_kermit.h" +#include "crc16_maxim.h" +#include "crc16_mcrf4xx.h" +#include "crc16_modbus.h" +#include "crc16_profibus.h" +#include "crc16_riello.h" +#include "crc16_t10dif.h" +#include "crc16_teledisk.h" +#include "crc16_tms37157.h" +#include "crc16_usb.h" +#include "crc16_x25.h" +#include "crc16_xmodem.h" +#include "crc32.h" +#include "crc32_bzip2.h" +#include "crc32_c.h" +#include "crc32_d.h" +#include "crc32_jamcrc.h" +#include "crc32_mpeg2.h" +#include "crc32_posix.h" +#include "crc32_q.h" +#include "crc32_xfer.h" +#include "crc64_ecma.h" +#include "crc8_ccitt.h" +#include "crc8_cdma2000.h" +#include "crc8_darc.h" +#include "crc8_dvbs2.h" +#include "crc8_ebu.h" +#include "crc8_icode.h" +#include "crc8_itu.h" +#include "crc8_maxim.h" +#include "crc8_rohc.h" +#include "crc8_wcdma.h" + +#endif diff --git a/include/etl/crc16.h b/include/etl/crc16.h index 55e12a58..f9c8cb2e 100644 --- a/include/etl/crc16.h +++ b/include/etl/crc16.h @@ -44,7 +44,7 @@ namespace etl using crc16_t = etl::crc_type; #else template - class crc16_t : public etl::private_crc::crc_type + class crc16_t : public etl::crc_type { public: diff --git a/include/etl/crc16_a.h b/include/etl/crc16_a.h index c9bf4fa4..2430c9f4 100644 --- a/include/etl/crc16_a.h +++ b/include/etl/crc16_a.h @@ -44,7 +44,7 @@ namespace etl using crc16_a_t = etl::crc_type; #else template - class crc16_a_t : public etl::private_crc::crc_type + class crc16_a_t : public etl::crc_type { public: diff --git a/include/etl/crc16_x25.h b/include/etl/crc16_x25.h index 829daa7f..afb705c0 100644 --- a/include/etl/crc16_x25.h +++ b/include/etl/crc16_x25.h @@ -44,7 +44,7 @@ namespace etl using crc16_x25_t = etl::crc_type; #else template - class crc16_x25_t : public etl::private_crc::crc_type + class crc16_x25_t : public etl::crc_type { public: diff --git a/include/etl/crc8_cdma2000.h b/include/etl/crc8_cdma2000.h index 34567d8f..d7a83108 100644 --- a/include/etl/crc8_cdma2000.h +++ b/include/etl/crc8_cdma2000.h @@ -44,7 +44,7 @@ namespace etl using crc8_cdma2000_t = etl::crc_type; #else template - class crc8_cdma2000_t : public etl::private_crc::crc_type + class crc8_cdma2000_t : public etl::crc_type { public: diff --git a/include/etl/crc8_darc.h b/include/etl/crc8_darc.h index 464bdc21..29a6a167 100644 --- a/include/etl/crc8_darc.h +++ b/include/etl/crc8_darc.h @@ -44,7 +44,7 @@ namespace etl using crc8_darc_t = etl::crc_type; #else template - class crc8_darc_t : public etl::private_crc::crc_type + class crc8_darc_t : public etl::crc_type { public: diff --git a/include/etl/crc8_dvbs2.h b/include/etl/crc8_dvbs2.h index 0ae5b6a1..02fe9f03 100644 --- a/include/etl/crc8_dvbs2.h +++ b/include/etl/crc8_dvbs2.h @@ -44,7 +44,7 @@ namespace etl using crc8_dvbs2_t = etl::crc_type; #else template - class crc8_dvbs2_t : public etl::private_crc::crc_type + class crc8_dvbs2_t : public etl::crc_type { public: diff --git a/include/etl/crc8_ebu.h b/include/etl/crc8_ebu.h index 4caf7686..3c4c7f2e 100644 --- a/include/etl/crc8_ebu.h +++ b/include/etl/crc8_ebu.h @@ -44,7 +44,7 @@ namespace etl using crc8_ebu_t = etl::crc_type; #else template - class crc8_ebu_t : public etl::private_crc::crc_type + class crc8_ebu_t : public etl::crc_type { public: diff --git a/include/etl/crc8_icode.h b/include/etl/crc8_icode.h index bfe21666..e421cc46 100644 --- a/include/etl/crc8_icode.h +++ b/include/etl/crc8_icode.h @@ -44,7 +44,7 @@ namespace etl using crc8_icode_t = etl::crc_type; #else template - class crc8_icode_t : public etl::private_crc::crc_type + class crc8_icode_t : public etl::crc_type { public: diff --git a/include/etl/crc8_itu.h b/include/etl/crc8_itu.h index eb0a2803..a4a7fc0c 100644 --- a/include/etl/crc8_itu.h +++ b/include/etl/crc8_itu.h @@ -44,7 +44,7 @@ namespace etl using crc8_itu_t = etl::crc_type; #else template - class crc8_itu_t : public etl::private_crc::crc_type + class crc8_itu_t : public etl::crc_type { public: diff --git a/include/etl/crc8_maxim.h b/include/etl/crc8_maxim.h index 84e5c4bf..bf39cd32 100644 --- a/include/etl/crc8_maxim.h +++ b/include/etl/crc8_maxim.h @@ -44,7 +44,7 @@ namespace etl using crc8_maxim_t = etl::crc_type; #else template - class crc8_maxim_t : public etl::private_crc::crc_type + class crc8_maxim_t : public etl::crc_type { public: diff --git a/include/etl/crc8_rohc.h b/include/etl/crc8_rohc.h index 79588eba..dcade461 100644 --- a/include/etl/crc8_rohc.h +++ b/include/etl/crc8_rohc.h @@ -44,7 +44,7 @@ namespace etl using crc8_rohc_t = etl::crc_type; #else template - class crc8_rohc_t : public etl::private_crc::crc_type + class crc8_rohc_t : public etl::crc_type { public: diff --git a/include/etl/crc8_wcdma.h b/include/etl/crc8_wcdma.h index 4ea1dc0b..a947e09a 100644 --- a/include/etl/crc8_wcdma.h +++ b/include/etl/crc8_wcdma.h @@ -44,7 +44,7 @@ namespace etl using crc8_wcdma_t = etl::crc_type; #else template - class crc8_wcdma_t : public etl::private_crc::crc_type + class crc8_wcdma_t : public etl::crc_type { public: diff --git a/include/etl/private/crc_parameters.h b/include/etl/private/crc_parameters.h index 343fd1d8..3634ddc3 100644 --- a/include/etl/private/crc_parameters.h +++ b/include/etl/private/crc_parameters.h @@ -86,6 +86,7 @@ namespace etl typedef crc_parameters crc16_teledisk_parameters; typedef crc_parameters crc16_tms37157_parameters; typedef crc_parameters crc16_a_parameters; + typedef crc_parameters crc16_arc_parameters; // 32 bit. typedef crc_parameters crc32_parameters; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 84100458..c857d47e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,7 +45,51 @@ set(TEST_SOURCE_FILES test_compiler_settings.cpp test_constant.cpp test_container.cpp - test_crc.cpp + test_crc.cpp + test_crc16.cpp + test_crc16_a.cpp + test_crc16_aug_ccitt.cpp + test_crc16_buypass.cpp + test_crc16_ccitt.cpp + test_crc16_cdma2000.cpp + test_crc16_dds110.cpp + test_crc16_dect_r.cpp + test_crc16_dect_x.cpp + test_crc16_dnp.cpp + test_crc16_en13757.cpp + test_crc16_genibus.cpp + test_crc16_kermit.cpp + test_crc16_maxim.cpp + test_crc16_mcrf4xx.cpp + test_crc16_modbus.cpp + test_crc16_profibus.cpp + test_crc16_riello.cpp + test_crc16_t10dif.cpp + test_crc16_teledisk.cpp + test_crc16_tms37157.cpp + test_crc16_usb.cpp + test_crc16_x25.cpp + test_crc16_xmodem.cpp + test_crc32.cpp + test_crc32_bzip2.cpp + test_crc32_c.cpp + test_crc32_d.cpp + test_crc32_jamcrc.cpp + test_crc32_mpeg2.cpp + test_crc32_posix.cpp + test_crc32_q.cpp + test_crc32_xfer.cpp + test_crc64_ecma.cpp + test_crc8_ccitt.cpp + test_crc8_cdma2000.cpp + test_crc8_darc.cpp + test_crc8_dvbs2.cpp + test_crc8_ebu.cpp + test_crc8_icode.cpp + test_crc8_itu.cpp + test_crc8_maxim.cpp + test_crc8_rohc.cpp + test_crc8_wcdma.cpp test_cumulative_moving_average.cpp test_cyclic_value.cpp test_debounce.cpp diff --git a/test/runtests.sh b/test/runtests.sh index 80091cf5..2bfee270 100755 --- a/test/runtests.sh +++ b/test/runtests.sh @@ -2,27 +2,40 @@ sudo ntpdate ntp.ubuntu.com cd build || exit 1 echo "ETL Tests" > etl_test_log.txt -echo "********** GCC **********" >> etl_test_log.txt +echo "" +echo "-----------------------------------------------" >> etl_test_log.txt +echo " GCC" >> etl_test_log.txt +echo "-----------------------------------------------" >> etl_test_log.txt gcc --version | grep gcc >> etl_test_log.txt -cmake --cmake-clean-cache -DNO_STL=OFF .. +CC=gcc CXX=g++ cmake --cmake-clean-cache -DNO_STL=OFF .. make ./etl_tests | tee etl_test_log.txt -echo "********** GCC - No STL **********" >> etl_test_log.txt +echo "" +echo "-----------------------------------------------" >> etl_test_log.txt +echo " GCC - No STL" >> etl_test_log.txt +echo "-----------------------------------------------" >> etl_test_log.txt gcc --version | grep gcc >> etl_test_log.txt -cmake --cmake-clean-cache -DNO_STL=ON .. +CC=gcc CXX=g++ cmake --cmake-clean-cache -DNO_STL=ON .. make ./etl_tests | tee etl_test_log.txt -echo "********** Clang **********" >> etl_test_log.txt +echo "" +echo "-----------------------------------------------" >> etl_test_log.txt +echo " Clang" >> etl_test_log.txt +echo "-----------------------------------------------" >> etl_test_log.txt clang --version | grep clang >> etl_test_log.txt -export CC=clang -export CXX=clang++ -cmake --cmake-clean-cache -DNO_STL=OFF .. +CC=clang CXX=clang++ cmake --cmake-clean-cache -DNO_STL=OFF .. make ./etl_tests | tee etl_test_log.txt -echo "********** Clang - No STL **********" >> etl_test_log.txt +echo "" +echo "-----------------------------------------------" >> etl_test_log.txt +echo " Clang - No STL" >> etl_test_log.txt +echo "-----------------------------------------------" >> etl_test_log.txt clang --version | grep clang >> etl_test_log.txt -export CC=clang -export CXX=clang++ -cmake --cmake-clean-cache -DNO_STL=ON .. +CC=clang CXX=clang++ cmake --cmake-clean-cache -DNO_STL=ON .. make ./etl_tests | tee etl_test_log.txt +echo "" +echo "-----------------------------------------------" >> etl_test_log.txt +echo " Tests Completed" >> etl_test_log.txt +echo "-----------------------------------------------" >> etl_test_log.txt + diff --git a/test/sanity-check/c++03/CMakeLists.txt b/test/sanity-check/c++03/CMakeLists.txt index fd6ecbc7..af5fb461 100644 --- a/test/sanity-check/c++03/CMakeLists.txt +++ b/test/sanity-check/c++03/CMakeLists.txt @@ -48,23 +48,51 @@ target_sources(t98 PRIVATE etl_profile.h ../compare.h.t.cpp ../constant.h.t.cpp ../container.h.t.cpp - ../crc16_aug_ccitt.h.t.cpp - ../crc16_ccitt.h.t.cpp - ../crc16_genibus.h.t.cpp ../crc16.h.t.cpp + ../crc16_a.h.t.cpp + ../crc16_arc.h.t.cpp + ../crc16_aug_ccitt.h.t.cpp + ../crc16_buypass.h.t.cpp + ../crc16_ccitt.h.t.cpp + ../crc16_cdma2000.h.t.cpp + ../crc16_dds110.h.t.cpp + ../crc16_dect_r.h.t.cpp + ../crc16_dect_x.h.t.cpp + ../crc16_dnp.h.t.cpp + ../crc16_en13757.h.t.cpp + ../crc16_genibus.h.t.cpp ../crc16_kermit.h.t.cpp + ../crc16_maxim.h.t.cpp + ../crc16_mcrf4xx.h.t.cpp ../crc16_modbus.h.t.cpp + ../crc16_profibus.h.t.cpp + ../crc16_riello.h.t.cpp + ../crc16_t10dif.h.t.cpp + ../crc16_teledisk.h.t.cpp + ../crc16_tms37157.h.t.cpp ../crc16_usb.h.t.cpp ../crc16_x25.h.t.cpp ../crc16_xmodem.h.t.cpp + ../crc32.h.t.cpp ../crc32_bzip2.h.t.cpp ../crc32_c.h.t.cpp - ../crc32.h.t.cpp + ../crc32_d.h.t.cpp + ../crc32_jamcrc.h.t.cpp ../crc32_mpeg2.h.t.cpp ../crc32_posix.h.t.cpp + ../crc32_q.h.t.cpp + ../crc32_xfer.h.t.cpp ../crc64_ecma.h.t.cpp ../crc8_ccitt.h.t.cpp + ../crc8_cdma2000.h.t.cpp + ../crc8_darc.h.t.cpp + ../crc8_dvbs2.h.t.cpp + ../crc8_ebu.h.t.cpp + ../crc8_icode.h.t.cpp + ../crc8_itu.h.t.cpp + ../crc8_maxim.h.t.cpp ../crc8_rohc.h.t.cpp + ../crc8_wcdma.h.t.cpp ../cumulative_moving_average.h.t.cpp ../cyclic_value.h.t.cpp ../debounce.h.t.cpp @@ -91,8 +119,8 @@ target_sources(t98 PRIVATE etl_profile.h ../forward_list.h.t.cpp ../frame_check_sequence.h.t.cpp ../fsm.h.t.cpp - ../functional.h.t.cpp ../function.h.t.cpp + ../functional.h.t.cpp ../generic_pool.h.t.cpp ../hash.h.t.cpp ../ihash.h.t.cpp @@ -119,17 +147,17 @@ target_sources(t98 PRIVATE etl_profile.h ../math_constants.h.t.cpp ../memory.h.t.cpp ../memory_model.h.t.cpp - ../message_bus.h.t.cpp ../message.h.t.cpp + ../message_bus.h.t.cpp ../message_packet.h.t.cpp ../message_router.h.t.cpp ../message_router_registry.h.t.cpp ../message_timer.h.t.cpp ../message_types.h.t.cpp - ../multi_array.h.t.cpp ../multimap.h.t.cpp - ../multi_range.h.t.cpp ../multiset.h.t.cpp + ../multi_array.h.t.cpp + ../multi_range.h.t.cpp ../murmur3.h.t.cpp ../mutex.h.t.cpp ../negative.h.t.cpp diff --git a/test/sanity-check/c++11/CMakeLists.txt b/test/sanity-check/c++11/CMakeLists.txt index 6988dfd1..449631f2 100644 --- a/test/sanity-check/c++11/CMakeLists.txt +++ b/test/sanity-check/c++11/CMakeLists.txt @@ -48,23 +48,51 @@ target_sources(t11 PRIVATE etl_profile.h ../compare.h.t.cpp ../constant.h.t.cpp ../container.h.t.cpp - ../crc16_aug_ccitt.h.t.cpp - ../crc16_ccitt.h.t.cpp - ../crc16_genibus.h.t.cpp ../crc16.h.t.cpp + ../crc16_a.h.t.cpp + ../crc16_arc.h.t.cpp + ../crc16_aug_ccitt.h.t.cpp + ../crc16_buypass.h.t.cpp + ../crc16_ccitt.h.t.cpp + ../crc16_cdma2000.h.t.cpp + ../crc16_dds110.h.t.cpp + ../crc16_dect_r.h.t.cpp + ../crc16_dect_x.h.t.cpp + ../crc16_dnp.h.t.cpp + ../crc16_en13757.h.t.cpp + ../crc16_genibus.h.t.cpp ../crc16_kermit.h.t.cpp + ../crc16_maxim.h.t.cpp + ../crc16_mcrf4xx.h.t.cpp ../crc16_modbus.h.t.cpp + ../crc16_profibus.h.t.cpp + ../crc16_riello.h.t.cpp + ../crc16_t10dif.h.t.cpp + ../crc16_teledisk.h.t.cpp + ../crc16_tms37157.h.t.cpp ../crc16_usb.h.t.cpp ../crc16_x25.h.t.cpp ../crc16_xmodem.h.t.cpp + ../crc32.h.t.cpp ../crc32_bzip2.h.t.cpp ../crc32_c.h.t.cpp - ../crc32.h.t.cpp + ../crc32_d.h.t.cpp + ../crc32_jamcrc.h.t.cpp ../crc32_mpeg2.h.t.cpp ../crc32_posix.h.t.cpp + ../crc32_q.h.t.cpp + ../crc32_xfer.h.t.cpp ../crc64_ecma.h.t.cpp ../crc8_ccitt.h.t.cpp + ../crc8_cdma2000.h.t.cpp + ../crc8_darc.h.t.cpp + ../crc8_dvbs2.h.t.cpp + ../crc8_ebu.h.t.cpp + ../crc8_icode.h.t.cpp + ../crc8_itu.h.t.cpp + ../crc8_maxim.h.t.cpp ../crc8_rohc.h.t.cpp + ../crc8_wcdma.h.t.cpp ../cumulative_moving_average.h.t.cpp ../cyclic_value.h.t.cpp ../debounce.h.t.cpp @@ -91,8 +119,8 @@ target_sources(t11 PRIVATE etl_profile.h ../forward_list.h.t.cpp ../frame_check_sequence.h.t.cpp ../fsm.h.t.cpp - ../functional.h.t.cpp ../function.h.t.cpp + ../functional.h.t.cpp ../generic_pool.h.t.cpp ../hash.h.t.cpp ../ihash.h.t.cpp @@ -119,17 +147,17 @@ target_sources(t11 PRIVATE etl_profile.h ../math_constants.h.t.cpp ../memory.h.t.cpp ../memory_model.h.t.cpp - ../message_bus.h.t.cpp ../message.h.t.cpp + ../message_bus.h.t.cpp ../message_packet.h.t.cpp ../message_router.h.t.cpp ../message_router_registry.h.t.cpp ../message_timer.h.t.cpp ../message_types.h.t.cpp - ../multi_array.h.t.cpp ../multimap.h.t.cpp - ../multi_range.h.t.cpp ../multiset.h.t.cpp + ../multi_array.h.t.cpp + ../multi_range.h.t.cpp ../murmur3.h.t.cpp ../mutex.h.t.cpp ../negative.h.t.cpp diff --git a/test/sanity-check/c++14/CMakeLists.txt b/test/sanity-check/c++14/CMakeLists.txt index e2254d0c..a8186231 100644 --- a/test/sanity-check/c++14/CMakeLists.txt +++ b/test/sanity-check/c++14/CMakeLists.txt @@ -22,6 +22,7 @@ set_target_properties(t14 PROPERTIES CXX_EXTENSIONS ON ) target_sources(t14 PRIVATE etl_profile.h + ../absolute.h.t.cpp ../algorithm.h.t.cpp ../alignment.h.t.cpp ../array.h.t.cpp @@ -47,23 +48,51 @@ target_sources(t14 PRIVATE etl_profile.h ../compare.h.t.cpp ../constant.h.t.cpp ../container.h.t.cpp - ../crc16_aug_ccitt.h.t.cpp - ../crc16_ccitt.h.t.cpp - ../crc16_genibus.h.t.cpp ../crc16.h.t.cpp + ../crc16_a.h.t.cpp + ../crc16_arc.h.t.cpp + ../crc16_aug_ccitt.h.t.cpp + ../crc16_buypass.h.t.cpp + ../crc16_ccitt.h.t.cpp + ../crc16_cdma2000.h.t.cpp + ../crc16_dds110.h.t.cpp + ../crc16_dect_r.h.t.cpp + ../crc16_dect_x.h.t.cpp + ../crc16_dnp.h.t.cpp + ../crc16_en13757.h.t.cpp + ../crc16_genibus.h.t.cpp ../crc16_kermit.h.t.cpp + ../crc16_maxim.h.t.cpp + ../crc16_mcrf4xx.h.t.cpp ../crc16_modbus.h.t.cpp + ../crc16_profibus.h.t.cpp + ../crc16_riello.h.t.cpp + ../crc16_t10dif.h.t.cpp + ../crc16_teledisk.h.t.cpp + ../crc16_tms37157.h.t.cpp ../crc16_usb.h.t.cpp ../crc16_x25.h.t.cpp ../crc16_xmodem.h.t.cpp + ../crc32.h.t.cpp ../crc32_bzip2.h.t.cpp ../crc32_c.h.t.cpp - ../crc32.h.t.cpp + ../crc32_d.h.t.cpp + ../crc32_jamcrc.h.t.cpp ../crc32_mpeg2.h.t.cpp ../crc32_posix.h.t.cpp + ../crc32_q.h.t.cpp + ../crc32_xfer.h.t.cpp ../crc64_ecma.h.t.cpp ../crc8_ccitt.h.t.cpp + ../crc8_cdma2000.h.t.cpp + ../crc8_darc.h.t.cpp + ../crc8_dvbs2.h.t.cpp + ../crc8_ebu.h.t.cpp + ../crc8_icode.h.t.cpp + ../crc8_itu.h.t.cpp + ../crc8_maxim.h.t.cpp ../crc8_rohc.h.t.cpp + ../crc8_wcdma.h.t.cpp ../cumulative_moving_average.h.t.cpp ../cyclic_value.h.t.cpp ../debounce.h.t.cpp @@ -90,8 +119,8 @@ target_sources(t14 PRIVATE etl_profile.h ../forward_list.h.t.cpp ../frame_check_sequence.h.t.cpp ../fsm.h.t.cpp - ../functional.h.t.cpp ../function.h.t.cpp + ../functional.h.t.cpp ../generic_pool.h.t.cpp ../hash.h.t.cpp ../ihash.h.t.cpp @@ -118,17 +147,17 @@ target_sources(t14 PRIVATE etl_profile.h ../math_constants.h.t.cpp ../memory.h.t.cpp ../memory_model.h.t.cpp - ../message_bus.h.t.cpp ../message.h.t.cpp + ../message_bus.h.t.cpp ../message_packet.h.t.cpp ../message_router.h.t.cpp ../message_router_registry.h.t.cpp ../message_timer.h.t.cpp ../message_types.h.t.cpp - ../multi_array.h.t.cpp ../multimap.h.t.cpp - ../multi_range.h.t.cpp ../multiset.h.t.cpp + ../multi_array.h.t.cpp + ../multi_range.h.t.cpp ../murmur3.h.t.cpp ../mutex.h.t.cpp ../negative.h.t.cpp diff --git a/test/sanity-check/c++17/CMakeLists.txt b/test/sanity-check/c++17/CMakeLists.txt index 0e8ed17b..27d346e6 100644 --- a/test/sanity-check/c++17/CMakeLists.txt +++ b/test/sanity-check/c++17/CMakeLists.txt @@ -22,6 +22,7 @@ set_target_properties(t17 PROPERTIES CXX_EXTENSIONS ON ) target_sources(t17 PRIVATE etl_profile.h + ../absolute.h.t.cpp ../algorithm.h.t.cpp ../alignment.h.t.cpp ../array.h.t.cpp @@ -47,23 +48,51 @@ target_sources(t17 PRIVATE etl_profile.h ../compare.h.t.cpp ../constant.h.t.cpp ../container.h.t.cpp - ../crc16_aug_ccitt.h.t.cpp - ../crc16_ccitt.h.t.cpp - ../crc16_genibus.h.t.cpp ../crc16.h.t.cpp + ../crc16_a.h.t.cpp + ../crc16_arc.h.t.cpp + ../crc16_aug_ccitt.h.t.cpp + ../crc16_buypass.h.t.cpp + ../crc16_ccitt.h.t.cpp + ../crc16_cdma2000.h.t.cpp + ../crc16_dds110.h.t.cpp + ../crc16_dect_r.h.t.cpp + ../crc16_dect_x.h.t.cpp + ../crc16_dnp.h.t.cpp + ../crc16_en13757.h.t.cpp + ../crc16_genibus.h.t.cpp ../crc16_kermit.h.t.cpp + ../crc16_maxim.h.t.cpp + ../crc16_mcrf4xx.h.t.cpp ../crc16_modbus.h.t.cpp + ../crc16_profibus.h.t.cpp + ../crc16_riello.h.t.cpp + ../crc16_t10dif.h.t.cpp + ../crc16_teledisk.h.t.cpp + ../crc16_tms37157.h.t.cpp ../crc16_usb.h.t.cpp ../crc16_x25.h.t.cpp ../crc16_xmodem.h.t.cpp + ../crc32.h.t.cpp ../crc32_bzip2.h.t.cpp ../crc32_c.h.t.cpp - ../crc32.h.t.cpp + ../crc32_d.h.t.cpp + ../crc32_jamcrc.h.t.cpp ../crc32_mpeg2.h.t.cpp ../crc32_posix.h.t.cpp + ../crc32_q.h.t.cpp + ../crc32_xfer.h.t.cpp ../crc64_ecma.h.t.cpp ../crc8_ccitt.h.t.cpp + ../crc8_cdma2000.h.t.cpp + ../crc8_darc.h.t.cpp + ../crc8_dvbs2.h.t.cpp + ../crc8_ebu.h.t.cpp + ../crc8_icode.h.t.cpp + ../crc8_itu.h.t.cpp + ../crc8_maxim.h.t.cpp ../crc8_rohc.h.t.cpp + ../crc8_wcdma.h.t.cpp ../cumulative_moving_average.h.t.cpp ../cyclic_value.h.t.cpp ../debounce.h.t.cpp @@ -90,8 +119,8 @@ target_sources(t17 PRIVATE etl_profile.h ../forward_list.h.t.cpp ../frame_check_sequence.h.t.cpp ../fsm.h.t.cpp - ../functional.h.t.cpp ../function.h.t.cpp + ../functional.h.t.cpp ../generic_pool.h.t.cpp ../hash.h.t.cpp ../ihash.h.t.cpp @@ -118,17 +147,17 @@ target_sources(t17 PRIVATE etl_profile.h ../math_constants.h.t.cpp ../memory.h.t.cpp ../memory_model.h.t.cpp - ../message_bus.h.t.cpp ../message.h.t.cpp + ../message_bus.h.t.cpp ../message_packet.h.t.cpp ../message_router.h.t.cpp ../message_router_registry.h.t.cpp ../message_timer.h.t.cpp ../message_types.h.t.cpp - ../multi_array.h.t.cpp ../multimap.h.t.cpp - ../multi_range.h.t.cpp ../multiset.h.t.cpp + ../multi_array.h.t.cpp + ../multi_range.h.t.cpp ../murmur3.h.t.cpp ../mutex.h.t.cpp ../negative.h.t.cpp diff --git a/test/sanity-check/crc16_a.h.t.cpp b/test/sanity-check/crc16_a.h.t.cpp new file mode 100644 index 00000000..4579142c --- /dev/null +++ b/test/sanity-check/crc16_a.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_arc.h.t.cpp b/test/sanity-check/crc16_arc.h.t.cpp new file mode 100644 index 00000000..2f74097b --- /dev/null +++ b/test/sanity-check/crc16_arc.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_buypass.h.t.cpp b/test/sanity-check/crc16_buypass.h.t.cpp new file mode 100644 index 00000000..b9f78cff --- /dev/null +++ b/test/sanity-check/crc16_buypass.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_cdma2000.h.t.cpp b/test/sanity-check/crc16_cdma2000.h.t.cpp new file mode 100644 index 00000000..55c1ab2c --- /dev/null +++ b/test/sanity-check/crc16_cdma2000.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 Bo Rydberg + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_dds110.h.t.cpp b/test/sanity-check/crc16_dds110.h.t.cpp new file mode 100644 index 00000000..232427a6 --- /dev/null +++ b/test/sanity-check/crc16_dds110.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_dect_r.h.t.cpp b/test/sanity-check/crc16_dect_r.h.t.cpp new file mode 100644 index 00000000..d71a09b6 --- /dev/null +++ b/test/sanity-check/crc16_dect_r.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_dect_x.h.t.cpp b/test/sanity-check/crc16_dect_x.h.t.cpp new file mode 100644 index 00000000..9e9aab33 --- /dev/null +++ b/test/sanity-check/crc16_dect_x.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_dnp.h.t.cpp b/test/sanity-check/crc16_dnp.h.t.cpp new file mode 100644 index 00000000..391735c1 --- /dev/null +++ b/test/sanity-check/crc16_dnp.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_en13757.h.t.cpp b/test/sanity-check/crc16_en13757.h.t.cpp new file mode 100644 index 00000000..d351edea --- /dev/null +++ b/test/sanity-check/crc16_en13757.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_maxim.h.t.cpp b/test/sanity-check/crc16_maxim.h.t.cpp new file mode 100644 index 00000000..4bfaad1b --- /dev/null +++ b/test/sanity-check/crc16_maxim.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 Bo Rydberg + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_mcrf4xx.h.t.cpp b/test/sanity-check/crc16_mcrf4xx.h.t.cpp new file mode 100644 index 00000000..f6eeeb64 --- /dev/null +++ b/test/sanity-check/crc16_mcrf4xx.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_profibus.h.t.cpp b/test/sanity-check/crc16_profibus.h.t.cpp new file mode 100644 index 00000000..c7a45a2b --- /dev/null +++ b/test/sanity-check/crc16_profibus.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_riello.h.t.cpp b/test/sanity-check/crc16_riello.h.t.cpp new file mode 100644 index 00000000..a69a6e5b --- /dev/null +++ b/test/sanity-check/crc16_riello.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_t10dif.h.t.cpp b/test/sanity-check/crc16_t10dif.h.t.cpp new file mode 100644 index 00000000..f42a8100 --- /dev/null +++ b/test/sanity-check/crc16_t10dif.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_teledisk.h.t.cpp b/test/sanity-check/crc16_teledisk.h.t.cpp new file mode 100644 index 00000000..23619476 --- /dev/null +++ b/test/sanity-check/crc16_teledisk.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc16_tms37157.h.t.cpp b/test/sanity-check/crc16_tms37157.h.t.cpp new file mode 100644 index 00000000..101c9284 --- /dev/null +++ b/test/sanity-check/crc16_tms37157.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc32_d.h.t.cpp b/test/sanity-check/crc32_d.h.t.cpp new file mode 100644 index 00000000..c991294e --- /dev/null +++ b/test/sanity-check/crc32_d.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc32_jamcrc.h.t.cpp b/test/sanity-check/crc32_jamcrc.h.t.cpp new file mode 100644 index 00000000..1c4c3bd0 --- /dev/null +++ b/test/sanity-check/crc32_jamcrc.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc32_q.h.t.cpp b/test/sanity-check/crc32_q.h.t.cpp new file mode 100644 index 00000000..157bf0cb --- /dev/null +++ b/test/sanity-check/crc32_q.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc32_xfer.h.t.cpp b/test/sanity-check/crc32_xfer.h.t.cpp new file mode 100644 index 00000000..9354dc39 --- /dev/null +++ b/test/sanity-check/crc32_xfer.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc8_cdma2000.h.t.cpp b/test/sanity-check/crc8_cdma2000.h.t.cpp new file mode 100644 index 00000000..e30b575f --- /dev/null +++ b/test/sanity-check/crc8_cdma2000.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 Bo Rydberg + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc8_darc.h.t.cpp b/test/sanity-check/crc8_darc.h.t.cpp new file mode 100644 index 00000000..0b1cbbcb --- /dev/null +++ b/test/sanity-check/crc8_darc.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc8_dvbs2.h.t.cpp b/test/sanity-check/crc8_dvbs2.h.t.cpp new file mode 100644 index 00000000..ee8fdded --- /dev/null +++ b/test/sanity-check/crc8_dvbs2.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc8_ebu.h.t.cpp b/test/sanity-check/crc8_ebu.h.t.cpp new file mode 100644 index 00000000..5d2fdb89 --- /dev/null +++ b/test/sanity-check/crc8_ebu.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc8_icode.h.t.cpp b/test/sanity-check/crc8_icode.h.t.cpp new file mode 100644 index 00000000..a12b5a6a --- /dev/null +++ b/test/sanity-check/crc8_icode.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc8_itu.h.t.cpp b/test/sanity-check/crc8_itu.h.t.cpp new file mode 100644 index 00000000..1fedadfc --- /dev/null +++ b/test/sanity-check/crc8_itu.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc8_maxim.h.t.cpp b/test/sanity-check/crc8_maxim.h.t.cpp new file mode 100644 index 00000000..de74e88b --- /dev/null +++ b/test/sanity-check/crc8_maxim.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/crc8_wcdma.h.t.cpp b/test/sanity-check/crc8_wcdma.h.t.cpp new file mode 100644 index 00000000..57bb911c --- /dev/null +++ b/test/sanity-check/crc8_wcdma.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/test_crc16_arc.cpp b/test/test_crc16_arc.cpp new file mode 100644 index 00000000..1e78b525 --- /dev/null +++ b/test/test_crc16_arc.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc16_arc.h" + +//***************************************************************************** +// The results for these tests were created from https://crccalc.com/ +//***************************************************************************** + +namespace +{ + SUITE(test_crc16_arc) + { + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc16_arc) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_arc(data.begin(), data.end()); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_add_values) + { + std::string data("123456789"); + + etl::crc16_arc crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_add_range) + { + std::string data("123456789"); + + etl::crc16_arc crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_arc crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_arc(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_arc((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_arc(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc16_arc_16) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_arc_t16(data.begin(), data.end()); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_16_add_values) + { + std::string data("123456789"); + + etl::crc16_arc_t16 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_16_add_range) + { + std::string data("123456789"); + + etl::crc16_arc_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_arc_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_16_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_arc_t16(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_arc_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_arc_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc16_arc_4) + { + std::string data("123456789"); + + uint16_t crc = etl::crc16_arc_t4(data.begin(), data.end()); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_4_add_values) + { + std::string data("123456789"); + + etl::crc16_arc_t4 crc_calculator; + + for (size_t i = 0; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint16_t crc = crc_calculator; + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_4_add_range) + { + std::string data("123456789"); + + etl::crc16_arc_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc16_arc_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint16_t crc = crc_calculator.value(); + + CHECK_EQUAL(0xBB3DU, crc); + } + + //************************************************************************* + TEST(test_crc16_arc_4_add_range_endian) + { + std::vector data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + std::vector data2 = { 0x04030201, 0x08070605 }; + std::vector data3 = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; + + uint16_t crc1 = etl::crc16_arc_t4(data1.begin(), data1.end()); + uint16_t crc2 = etl::crc16_arc_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(crc1, crc2); + + uint16_t crc3 = etl::crc16_arc_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(crc1, crc3); + } + }; +} + diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 9d83ee4a..ca2283ce 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1258,16 +1258,29 @@ + + + + + + + + + + + + + @@ -1285,6 +1298,7 @@ + @@ -1860,6 +1874,32 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + true true @@ -1872,6 +1912,7 @@ true true + true true @@ -1884,6 +1925,72 @@ true true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + true true @@ -1908,6 +2015,32 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + true true @@ -1920,6 +2053,71 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + true true @@ -1992,6 +2190,32 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + true true @@ -2016,6 +2240,32 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + true true @@ -2040,6 +2290,97 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + + + true + true + true + true + true + true + true + true + true + true + true + true true @@ -2052,6 +2393,19 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + true true @@ -3791,6 +4145,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 413af252..8ac738f9 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1017,6 +1017,48 @@ ETL\Maths + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + + + ETL\Maths + @@ -2264,6 +2306,93 @@ Source Files + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files\Sanity Checks + + + Source Files +