Merge branch 'pull-request/#812-Implement-SAE-J1850-CRC8' into development

This commit is contained in:
John Wellbelove 2024-01-18 08:58:15 +00:00
commit 4b39d012be
17 changed files with 828 additions and 2 deletions

View File

@ -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

View File

@ -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"

79
include/etl/crc8_j1850.h Normal file
View File

@ -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 <size_t Table_Size>
using crc8_j1850_t = etl::crc_type<etl::private_crc::crc8_j1850_parameters, Table_Size>;
#else
template <size_t Table_Size>
class crc8_j1850_t : public etl::crc_type<etl::private_crc::crc8_j1850_parameters, Table_Size>
{
public:
//*************************************************************************
/// Default constructor.
//*************************************************************************
crc8_j1850_t()
{
this->reset();
}
//*************************************************************************
/// Constructor from range.
/// \param begin Start of the range.
/// \param end End of the range.
//*************************************************************************
template<typename TIterator>
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

View File

@ -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 <size_t Table_Size>
using crc8_j1850_zero_t = etl::crc_type<etl::private_crc::crc8_j1850_zero_parameters, Table_Size>;
#else
template <size_t Table_Size>
class crc8_j1850_zero_t : public etl::crc_type<etl::private_crc::crc8_j1850_zero_parameters, Table_Size>
{
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<typename TIterator>
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

View File

@ -79,6 +79,8 @@ namespace etl
typedef crc_parameters<uint8_t, 0x07U, 0x00U, 0x55U, false> crc8_itu_parameters;
typedef crc_parameters<uint8_t, 0x31U, 0x00U, 0x00U, true> crc8_maxim_parameters;
typedef crc_parameters<uint8_t, 0x9BU, 0x00U, 0x00U, true> crc8_wcdma_parameters;
typedef crc_parameters<uint8_t, 0x1DU, 0xFFU, 0xFFU, false> crc8_j1850_parameters;
typedef crc_parameters<uint8_t, 0x1DU, 0x00U, 0x00U, false> crc8_j1850_zero_parameters;
// 16 bit.
typedef crc_parameters<uint16_t, 0x8005U, 0x0000U, 0x0000U, true> crc16_parameters;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <etl/crc8_j1850.h>

View File

@ -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 <etl/crc8_j1850_zero.h>

263
test/test_crc8_j1850.cpp Normal file
View File

@ -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 <iterator>
#include <string>
#include <vector>
#include <stdint.h>
#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<uint8_t> data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U };
std::vector<uint32_t> data2 = { 0x04030201UL, 0x08070605UL };
std::vector<uint8_t> 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<uint8_t> data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U };
std::vector<uint32_t> data2 = { 0x04030201UL, 0x08070605UL };
std::vector<uint8_t> 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<uint8_t> data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U };
std::vector<uint32_t> data2 = { 0x04030201UL, 0x08070605UL };
std::vector<uint8_t> 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));
}
};
}

View File

@ -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 <iterator>
#include <string>
#include <vector>
#include <stdint.h>
#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<uint8_t> data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U };
std::vector<uint32_t> data2 = { 0x04030201UL, 0x08070605UL };
std::vector<uint8_t> 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<uint8_t> data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U };
std::vector<uint32_t> data2 = { 0x04030201UL, 0x08070605UL };
std::vector<uint8_t> 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<uint8_t> data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U };
std::vector<uint32_t> data2 = { 0x04030201UL, 0x08070605UL };
std::vector<uint8_t> 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));
}
};
}

View File

@ -2994,6 +2994,8 @@
<ClInclude Include="..\..\include\etl\crc8_ebu.h" />
<ClInclude Include="..\..\include\etl\crc8_icode.h" />
<ClInclude Include="..\..\include\etl\crc8_itu.h" />
<ClInclude Include="..\..\include\etl\crc8_j1850.h" />
<ClInclude Include="..\..\include\etl\crc8_j1850_zero.h" />
<ClInclude Include="..\..\include\etl\crc8_maxim.h" />
<ClInclude Include="..\..\include\etl\crc8_rohc.h" />
<ClInclude Include="..\..\include\etl\crc8_wcdma.h" />
@ -4735,6 +4737,34 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\syntax_check\crc8_j1850.h.t.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual imessage|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++ 20 - No Tests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - No STL - Optimised -O2|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - Optimised O2|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual messages|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\syntax_check\crc8_j1850_zero.h.t.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual imessage|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++ 20 - No Tests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - No STL - Optimised -O2|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - Optimised O2|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual messages|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\syntax_check\crc8_maxim.h.t.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual imessage|Win32'">true</ExcludedFromBuild>
@ -7354,6 +7384,8 @@
<ClCompile Include="..\test_crc8_ebu.cpp" />
<ClCompile Include="..\test_crc8_icode.cpp" />
<ClCompile Include="..\test_crc8_itu.cpp" />
<ClCompile Include="..\test_crc8_j1850.cpp" />
<ClCompile Include="..\test_crc8_j1850_zero.cpp" />
<ClCompile Include="..\test_crc8_maxim.cpp" />
<ClCompile Include="..\test_crc8_rohc.cpp" />
<ClCompile Include="..\test_crc8_wcdma.cpp" />

View File

@ -1389,6 +1389,12 @@
<ClInclude Include="..\..\include\etl\crc1.h">
<Filter>ETL\Maths\CRC</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\crc8_j1850.h">
<Filter>ETL\Maths\CRC</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\crc8_j1850_zero.h">
<Filter>ETL\Maths\CRC</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\test_string_char.cpp">
@ -3284,6 +3290,18 @@
<ClCompile Include="..\test_crc1.cpp">
<Filter>Tests\CRC</Filter>
</ClCompile>
<ClCompile Include="..\syntax_check\crc8_j1850.h.t.cpp">
<Filter>Tests\Syntax Checks\Source</Filter>
</ClCompile>
<ClCompile Include="..\syntax_check\crc8_j1850_zero.h.t.cpp">
<Filter>Tests\Syntax Checks\Source</Filter>
</ClCompile>
<ClCompile Include="..\test_crc8_j1850.cpp">
<Filter>Tests\CRC</Filter>
</ClCompile>
<ClCompile Include="..\test_crc8_j1850_zero.cpp">
<Filter>Tests\CRC</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\library.properties">