datacheckhelper.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // // ******************************************************************
  2. // // /\ /| @File datacheckhelper.cc
  3. // // \ V/ @Brief
  4. // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
  5. // // / | @Creation 2024-05-16
  6. // // / \\ @Modified 2024-06-24
  7. // // *(__\_\
  8. // // ******************************************************************
  9. #include "data_check_helper.h"
  10. #include <cmath>
  11. #include "Constants.h"
  12. namespace Protocol
  13. {
  14. bool DataCheckHelper::CheckDataByOddEven(uint8_t data, int32_t data_bit_count,
  15. const OddEvenCheck check_type)
  16. {
  17. if (check_type == OddEvenCheck::None) return true;
  18. bool temp = false;
  19. while (data_bit_count > 0)
  20. {
  21. temp ^= ((data & 0b01) == 1);
  22. data >>= 1;
  23. data_bit_count--;
  24. }
  25. if (check_type == OddEvenCheck::Odd) temp = !temp;
  26. return temp;
  27. }
  28. bool DataCheckHelper::CheckDoubleIsEqual(const double a, const double b)
  29. {
  30. return fabs(a - b) < FLOAT_EQUAL_EPSILON;
  31. }
  32. }