1234567891011121314151617181920212223242526272829303132333435363738 |
- // // ******************************************************************
- // // /\ /| @File datacheckhelper.cc
- // // \ V/ @Brief
- // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
- // // / | @Creation 2024-05-16
- // // / \\ @Modified 2024-06-24
- // // *(__\_\
- // // ******************************************************************
- #include "data_check_helper.h"
- #include <cmath>
- #include "Constants.h"
- namespace Protocol
- {
- bool DataCheckHelper::CheckDataByOddEven(uint8_t data, int32_t data_bit_count,
- const OddEvenCheck check_type)
- {
- if (check_type == OddEvenCheck::None) return true;
- bool temp = false;
- while (data_bit_count > 0)
- {
- temp ^= ((data & 0b01) == 1);
- data >>= 1;
- data_bit_count--;
- }
- if (check_type == OddEvenCheck::Odd) temp = !temp;
- return temp;
- }
- bool DataCheckHelper::CheckDoubleIsEqual(const double a, const double b)
- {
- return fabs(a - b) < FLOAT_EQUAL_EPSILON;
- }
- }
|