DataCheckHelper.cpp 963 B

123456789101112131415161718192021222324252627282930
  1. // // ******************************************************************
  2. // // /\ /| @File DataCheckHelper.cpp
  3. // // \ V/ @Brief
  4. // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
  5. // // / | @Creation 2024-05-16
  6. // // / \\ @Modified 2024-05-16
  7. // // *(__\_\
  8. // // ******************************************************************
  9. #include "DataCheckHelper.h"
  10. namespace Protocol
  11. {
  12. bool DataCheckHelper::CheckDataByOddEven(uint8_t data, int32_t dataBitCount,
  13. const OddEvenCheck checkType)
  14. {
  15. if (checkType == OddEvenCheck::None) return true;
  16. bool temp = false;
  17. while (dataBitCount > 0)
  18. {
  19. temp ^= ((data & 0b01) == 1);
  20. data >>= 1;
  21. dataBitCount--;
  22. }
  23. if (checkType == OddEvenCheck::Odd) temp = !temp;
  24. return temp;
  25. }
  26. }