From 0f1840a70d11a3d317afa55b8361829b93c8eeb8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 10 Jan 2024 08:51:03 +0000 Subject: [PATCH 1/3] Update LICENSE --- LICENSE | 2 -- 1 file changed, 2 deletions(-) diff --git a/LICENSE b/LICENSE index 0e19085c8..d13cc4b26 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,5 @@ The MIT License (MIT) -Copyright (c) 2016 jwellbelove, https://github.com/ETLCPP/etl, http://www.etlcpp.com - 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 From ac4c3e67e6e98cd0cf499525bd693bbba18e1009 Mon Sep 17 00:00:00 2001 From: Drew Rife Date: Sat, 13 Jan 2024 06:48:55 -0500 Subject: [PATCH 2/3] Implement SAE J1850 CRC8 and "Zero" version (#812) * feat: added 8bit j1850 crc parameters * feat: add crc8 j1850 header * feat: add crc j1850 zero header * feat: add the crc j1850 headers to crc.h * test: j1850 4 constructor * build: crc8 j1850 tests * test: crc8 j1850 4 add values * test: crc8 j1850 4 add range * test: crc8 j1850 4 add range via iterator * test: crc8 j1850 4 add range endian * test: crc8 j1850 16 constructor * test: crc8 j1850 16 add values * test: crc8 j1850 16 add range * test: crc8 j1850 16 add range via iterator * test: crc8 j1850 16 add range endian * test: crc8 j1850 156 constructor * test: crc8 j1850 256 add values * test: crc8 j1850 256 add range * test: crc8 j1850 add range via iterator * test: crc8 j1850 256 add range endian * test: initial commit of crc j1850 zero tests * build: crc8 j1850 zero tests * test: crc8 j1850 zero 4 add values * test: crc8 j1850 zero 4 add range * test: crc8 j1850 zero 4 add range via iterator * test: crc8 j1850 zero 4 add range endian * test: crc8 j1850 zero 16 constructor * test: crc8 j1850 zero 16 add values * test: crc8 j1850 zero 16 add range * test: crc8 j1850 zero 16 add range via iterator * test: crc8 j1850 zero 16 add range endian * test: crc8 j1850 zero 256 constructor * test: crc8 j1850 zero 256 add values * test: crc8 j1850 zero 256 add range * test: crc8 j1850 zero 256 add range via iterator * test: crc8 j1850 zero 256 add range endian * fix: header include guards --- include/etl/crc.h | 2 + include/etl/crc8_j1850.h | 79 ++++++++ include/etl/crc8_j1850_zero.h | 79 ++++++++ include/etl/private/crc_parameters.h | 2 + test/CMakeLists.txt | 2 + test/test_crc8_j1850.cpp | 263 +++++++++++++++++++++++++++ test/test_crc8_j1850_zero.cpp | 263 +++++++++++++++++++++++++++ 7 files changed, 690 insertions(+) create mode 100644 include/etl/crc8_j1850.h create mode 100644 include/etl/crc8_j1850_zero.h create mode 100644 test/test_crc8_j1850.cpp create mode 100644 test/test_crc8_j1850_zero.cpp diff --git a/include/etl/crc.h b/include/etl/crc.h index eab6d7bc2..78ceb5526 100644 --- a/include/etl/crc.h +++ b/include/etl/crc.h @@ -40,6 +40,8 @@ SOFTWARE. #include "crc8_ebu.h" #include "crc8_icode.h" #include "crc8_itu.h" +#include "crc8_j1850_zero.h" +#include "crc8_j1850.h" #include "crc8_maxim.h" #include "crc8_rohc.h" #include "crc8_wcdma.h" diff --git a/include/etl/crc8_j1850.h b/include/etl/crc8_j1850.h new file mode 100644 index 000000000..723a29528 --- /dev/null +++ b/include/etl/crc8_j1850.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 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. +******************************************************************************/ + +#ifndef ETL_CRC8_J1850_INCLUDED +#define ETL_CRC8_J1850_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup SAE J1850 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_USING_CPP11 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + template + using crc8_j1850_t = etl::crc_type; +#else + template + class crc8_j1850_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_j1850_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_j1850_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_j1850_t<256U> crc8_j1850_t256; + typedef etl::crc8_j1850_t<16U> crc8_j1850_t16; + typedef etl::crc8_j1850_t<4U> crc8_j1850_t4; + typedef crc8_j1850_t256 crc8_j1850; +} + +#endif diff --git a/include/etl/crc8_j1850_zero.h b/include/etl/crc8_j1850_zero.h new file mode 100644 index 000000000..04bd7b556 --- /dev/null +++ b/include/etl/crc8_j1850_zero.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 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. +******************************************************************************/ + +#ifndef ETL_CRC8_J1850_ZERO_INCLUDED +#define ETL_CRC8_J1850_ZERO_INCLUDED + +#include "platform.h" +#include "private/crc_implementation.h" + +///\defgroup SAE J1850 Zero 8 bit CRC calculation +///\ingroup crc + +namespace etl +{ +#if ETL_USING_CPP11 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) + template + using crc8_j1850_zero_t = etl::crc_type; +#else + template + class crc8_j1850_zero_t : public etl::crc_type + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + crc8_j1850_zero_t() + { + this->reset(); + } + + //************************************************************************* + /// Constructor from range. + /// \param begin Start of the range. + /// \param end End of the range. + //************************************************************************* + template + crc8_j1850_zero_t(TIterator begin, const TIterator end) + { + this->reset(); + this->add(begin, end); + } + }; +#endif + + typedef etl::crc8_j1850_zero_t<256U> crc8_j1850_zero_t256; + typedef etl::crc8_j1850_zero_t<16U> crc8_j1850_zero_t16; + typedef etl::crc8_j1850_zero_t<4U> crc8_j1850_zero_t4; + typedef crc8_j1850_zero_t256 crc8_j1850_zero; +} + +#endif diff --git a/include/etl/private/crc_parameters.h b/include/etl/private/crc_parameters.h index 72cd1ef56..705684c06 100644 --- a/include/etl/private/crc_parameters.h +++ b/include/etl/private/crc_parameters.h @@ -79,6 +79,8 @@ namespace etl typedef crc_parameters crc8_itu_parameters; typedef crc_parameters crc8_maxim_parameters; typedef crc_parameters crc8_wcdma_parameters; + typedef crc_parameters crc8_j1850_parameters; + typedef crc_parameters crc8_j1850_zero_parameters; // 16 bit. typedef crc_parameters crc16_parameters; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4869a7c89..e8afb2692 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -98,6 +98,8 @@ add_executable(etl_tests test_crc8_ebu.cpp test_crc8_icode.cpp test_crc8_itu.cpp + test_crc8_j1850_zero.cpp + test_crc8_j1850.cpp test_crc8_maxim.cpp test_crc8_rohc.cpp test_crc8_wcdma.cpp diff --git a/test/test_crc8_j1850.cpp b/test/test_crc8_j1850.cpp new file mode 100644 index 000000000..1b50b14a5 --- /dev/null +++ b/test/test_crc8_j1850.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +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 "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_j1850.h" + +//***************************************************************************** +// The results for these tests were created from http://www.sunshine2k.de/coding/javascript/crc/crc_js.html +//***************************************************************************** + +namespace +{ + SUITE(test_crc_crc8_j1850) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_j1850_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_j1850_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_4_add_values) + { + std::string data("123456789"); + + etl::crc8_j1850_t4 crc_calculator; + + for (size_t i = 0UL; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_4_add_range) + { + std::string data("123456789"); + + etl::crc8_j1850_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j18_50_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_j1850_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_4_add_range_endian) + { + std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; + std::vector data2 = { 0x04030201UL, 0x08070605UL }; + std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; + + uint8_t crc1 = etl::crc8_j1850_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_j1850_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_j1850_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_j1850_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_j1850_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_16_add_values) + { + std::string data("123456789"); + + etl::crc8_j1850_t16 crc_calculator; + + for (size_t i = 0UL; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_16_add_range) + { + std::string data("123456789"); + + etl::crc8_j1850_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_j1850_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_16_add_range_endian) + { + std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; + std::vector data2 = { 0x04030201UL, 0x08070605UL }; + std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; + + uint8_t crc1 = etl::crc8_j1850_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_j1850_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_j1850_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_j1850_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_j1850(data.begin(), data.end()); + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_256_add_values) + { + std::string data("123456789"); + + etl::crc8_j1850 crc_calculator; + + for (size_t i = 0UL; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_256_add_range) + { + std::string data("123456789"); + + etl::crc8_j1850 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_j1850 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x4BU, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_256_add_range_endian) + { + std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; + std::vector data2 = { 0x04030201UL, 0x08070605UL }; + std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; + + uint8_t crc1 = etl::crc8_j1850(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_j1850((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_j1850(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + diff --git a/test/test_crc8_j1850_zero.cpp b/test/test_crc8_j1850_zero.cpp new file mode 100644 index 000000000..3ab0bae36 --- /dev/null +++ b/test/test_crc8_j1850_zero.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +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 "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/crc8_j1850_zero.h" + +//***************************************************************************** +// The results for these tests were created from http://www.sunshine2k.de/coding/javascript/crc/crc_js.html +//***************************************************************************** + +namespace +{ + SUITE(test_crc_crc8_j1850_zero) + { + //************************************************************************* + // Table size 4 + //************************************************************************* + TEST(test_crc8_j1850_zero_4_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_j1850_zero_t4(data.begin(), data.end()); + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_4_add_values) + { + std::string data("123456789"); + + etl::crc8_j1850_zero_t4 crc_calculator; + + for (size_t i = 0UL; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_4_add_range) + { + std::string data("123456789"); + + etl::crc8_j1850_zero_t4 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_4_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_j1850_zero_t4 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_4_add_range_endian) + { + std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; + std::vector data2 = { 0x04030201UL, 0x08070605UL }; + std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; + + uint8_t crc1 = etl::crc8_j1850_zero_t4(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_j1850_zero_t4((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_j1850_zero_t4(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 16 + //************************************************************************* + TEST(test_crc8_j1850_zero_16_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_j1850_zero_t16(data.begin(), data.end()); + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_16_add_values) + { + std::string data("123456789"); + + etl::crc8_j1850_zero_t16 crc_calculator; + + for (size_t i = 0UL; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_16_add_range) + { + std::string data("123456789"); + + etl::crc8_j1850_zero_t16 crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_16_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_j1850_zero_t16 crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_16_add_range_endian) + { + std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; + std::vector data2 = { 0x04030201UL, 0x08070605UL }; + std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; + + uint8_t crc1 = etl::crc8_j1850_zero_t16(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_j1850_zero_t16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_j1850_zero_t16(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + + //************************************************************************* + // Table size 256 + //************************************************************************* + TEST(test_crc8_j1850_zero_256_constructor) + { + std::string data("123456789"); + + uint8_t crc = etl::crc8_j1850_zero(data.begin(), data.end()); + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_256_add_values) + { + std::string data("123456789"); + + etl::crc8_j1850_zero crc_calculator; + + for (size_t i = 0UL; i < data.size(); ++i) + { + crc_calculator.add(data[i]); + } + + uint8_t crc = crc_calculator; + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_256_add_range) + { + std::string data("123456789"); + + etl::crc8_j1850_zero crc_calculator; + + crc_calculator.add(data.begin(), data.end()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_256_add_range_via_iterator) + { + std::string data("123456789"); + + etl::crc8_j1850_zero crc_calculator; + + std::copy(data.begin(), data.end(), crc_calculator.input()); + + uint8_t crc = crc_calculator.value(); + + CHECK_EQUAL(0x37U, int(crc)); + } + + //************************************************************************* + TEST(test_crc8_j1850_zero_256_add_range_endian) + { + std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; + std::vector data2 = { 0x04030201UL, 0x08070605UL }; + std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; + + uint8_t crc1 = etl::crc8_j1850_zero(data1.begin(), data1.end()); + uint8_t crc2 = etl::crc8_j1850_zero((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); + CHECK_EQUAL(int(crc1), int(crc2)); + + uint8_t crc3 = etl::crc8_j1850_zero(data3.rbegin(), data3.rend()); + CHECK_EQUAL(int(crc1), int(crc3)); + } + }; +} + From 279a59fa5951d5330845cf3f10f717a17986da51 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 18 Jan 2024 08:57:50 +0000 Subject: [PATCH 3/3] Added syntax checks for crc8_j1850 & crc8_j1850_zero --- test/syntax_check/c++03/CMakeLists.txt | 6 +++ test/syntax_check/c++11/CMakeLists.txt | 6 +++ test/syntax_check/c++14/CMakeLists.txt | 6 +++ test/syntax_check/c++17/CMakeLists.txt | 6 +++ test/syntax_check/c++20/CMakeLists.txt | 6 +++ test/syntax_check/crc8_j1850.h.t.cpp | 29 ++++++++++++++ test/syntax_check/crc8_j1850_zero.h.t.cpp | 29 ++++++++++++++ test/vs2022/etl.vcxproj | 32 +++++++++++++++ test/vs2022/etl.vcxproj.filters | 48 ++++++++++++++++++++--- 9 files changed, 162 insertions(+), 6 deletions(-) create mode 100644 test/syntax_check/crc8_j1850.h.t.cpp create mode 100644 test/syntax_check/crc8_j1850_zero.h.t.cpp diff --git a/test/syntax_check/c++03/CMakeLists.txt b/test/syntax_check/c++03/CMakeLists.txt index 0b63c6b21..7a425be17 100644 --- a/test/syntax_check/c++03/CMakeLists.txt +++ b/test/syntax_check/c++03/CMakeLists.txt @@ -38,6 +38,10 @@ set_target_properties(t98 PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON ) +target_compile_options(t98 + PRIVATE + -fsyntax-only + ) target_sources(t98 PRIVATE etl_profile.h ../absolute.h.t.cpp ../algorithm.h.t.cpp @@ -123,6 +127,8 @@ target_sources(t98 PRIVATE etl_profile.h ../crc8_maxim.h.t.cpp ../crc8_rohc.h.t.cpp ../crc8_wcdma.h.t.cpp + ../crc8_j1850.h.t.cpp + ../crc8_j1850_zero.h.t.cpp ../cyclic_value.h.t.cpp ../debounce.h.t.cpp ../debug_count.h.t.cpp diff --git a/test/syntax_check/c++11/CMakeLists.txt b/test/syntax_check/c++11/CMakeLists.txt index 72900939b..29dc304ed 100644 --- a/test/syntax_check/c++11/CMakeLists.txt +++ b/test/syntax_check/c++11/CMakeLists.txt @@ -38,6 +38,10 @@ set_target_properties(t11 PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON ) +target_compile_options(t11 + PRIVATE + -fsyntax-only + ) target_sources(t11 PRIVATE etl_profile.h ../absolute.h.t.cpp ../algorithm.h.t.cpp @@ -123,6 +127,8 @@ target_sources(t11 PRIVATE etl_profile.h ../crc8_maxim.h.t.cpp ../crc8_rohc.h.t.cpp ../crc8_wcdma.h.t.cpp + ../crc8_j1850.h.t.cpp + ../crc8_j1850_zero.h.t.cpp ../cyclic_value.h.t.cpp ../debounce.h.t.cpp ../debug_count.h.t.cpp diff --git a/test/syntax_check/c++14/CMakeLists.txt b/test/syntax_check/c++14/CMakeLists.txt index e9fb7a4eb..9df6214cb 100644 --- a/test/syntax_check/c++14/CMakeLists.txt +++ b/test/syntax_check/c++14/CMakeLists.txt @@ -38,6 +38,10 @@ set_target_properties(t14 PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON ) +target_compile_options(t14 + PRIVATE + -fsyntax-only + ) target_sources(t14 PRIVATE etl_profile.h ../absolute.h.t.cpp ../algorithm.h.t.cpp @@ -123,6 +127,8 @@ target_sources(t14 PRIVATE etl_profile.h ../crc8_maxim.h.t.cpp ../crc8_rohc.h.t.cpp ../crc8_wcdma.h.t.cpp + ../crc8_j1850.h.t.cpp + ../crc8_j1850_zero.h.t.cpp ../cyclic_value.h.t.cpp ../debounce.h.t.cpp ../debug_count.h.t.cpp diff --git a/test/syntax_check/c++17/CMakeLists.txt b/test/syntax_check/c++17/CMakeLists.txt index 4ab127cee..6be7bb03b 100644 --- a/test/syntax_check/c++17/CMakeLists.txt +++ b/test/syntax_check/c++17/CMakeLists.txt @@ -38,6 +38,10 @@ set_target_properties(t17 PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON ) +target_compile_options(t17 + PRIVATE + -fsyntax-only + ) target_sources(t17 PRIVATE etl_profile.h ../absolute.h.t.cpp ../algorithm.h.t.cpp @@ -123,6 +127,8 @@ target_sources(t17 PRIVATE etl_profile.h ../crc8_maxim.h.t.cpp ../crc8_rohc.h.t.cpp ../crc8_wcdma.h.t.cpp + ../crc8_j1850.h.t.cpp + ../crc8_j1850_zero.h.t.cpp ../cyclic_value.h.t.cpp ../debounce.h.t.cpp ../debug_count.h.t.cpp diff --git a/test/syntax_check/c++20/CMakeLists.txt b/test/syntax_check/c++20/CMakeLists.txt index f5046f87a..6c36b9d55 100644 --- a/test/syntax_check/c++20/CMakeLists.txt +++ b/test/syntax_check/c++20/CMakeLists.txt @@ -38,6 +38,10 @@ set_target_properties(t20 PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON ) +target_compile_options(t20 + PRIVATE + -fsyntax-only + ) target_sources(t20 PRIVATE etl_profile.h ../absolute.h.t.cpp ../algorithm.h.t.cpp @@ -123,6 +127,8 @@ target_sources(t20 PRIVATE etl_profile.h ../crc8_maxim.h.t.cpp ../crc8_rohc.h.t.cpp ../crc8_wcdma.h.t.cpp + ../crc8_j1850.h.t.cpp + ../crc8_j1850_zero.h.t.cpp ../cyclic_value.h.t.cpp ../debounce.h.t.cpp ../debug_count.h.t.cpp diff --git a/test/syntax_check/crc8_j1850.h.t.cpp b/test/syntax_check/crc8_j1850.h.t.cpp new file mode 100644 index 000000000..5e16709f4 --- /dev/null +++ b/test/syntax_check/crc8_j1850.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) 2024 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/syntax_check/crc8_j1850_zero.h.t.cpp b/test/syntax_check/crc8_j1850_zero.h.t.cpp new file mode 100644 index 000000000..ec892d09e --- /dev/null +++ b/test/syntax_check/crc8_j1850_zero.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) 2024 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/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 4c18142c7..46b7b05cb 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -2994,6 +2994,8 @@ + + @@ -4735,6 +4737,34 @@ 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 @@ -7354,6 +7384,8 @@ + + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 2adfa8622..cad865ea7 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1389,6 +1389,12 @@ ETL\Maths\CRC + + ETL\Maths\CRC + + + ETL\Maths\CRC + @@ -3284,6 +3290,18 @@ Tests\CRC + + Tests\Syntax Checks\Source + + + Tests\Syntax Checks\Source + + + Tests\CRC + + + Tests\CRC + @@ -3340,12 +3358,6 @@ Resource Files\CI\Appveyor - - Resource Files\CI\Github - - - Resource Files\CI\Github - Resource Files @@ -3412,6 +3424,30 @@ Tests\Scripts + + Resource Files\CI\Github + + + Resource Files\CI\Github + + + Resource Files\CI\Github + + + Resource Files\CI\Github + + + Resource Files\CI\Github + + + Resource Files\CI\Github + + + Resource Files\CI\Github + + + Resource Files\CI\Github +