edge_pulse.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // // ******************************************************************
  2. // // /\ /| @File edge_pulse.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 "edge_pulse.h"
  10. namespace Protocol
  11. {
  12. // int32_t EdgePulse::GetLength() const
  13. // {
  14. // return EndIndex > StartIndex && StartIndex > 0 ? EndIndex - StartIndex : 0;
  15. // }
  16. // TwoLevelEdgePulse::TwoLevelEdgePulse(TwoLevelEdgePulseStatusType current)
  17. // {
  18. // CurrentLevel = current;
  19. // }
  20. ThreeLevelEdgePulseStatusType ThreeLevelEdgePulse::ConvertToStatus(const bool high_level, const bool low_loglevel)
  21. {
  22. return static_cast<ThreeLevelEdgePulseStatusType>((high_level ? 1 : 0) << 1 | (low_loglevel ? 1 : 0));
  23. }
  24. ThreeLevelEdgePulse::ThreeLevelEdgePulse(const ThreeLevelEdgePulseStatusType current)
  25. {
  26. current_level = current;
  27. }
  28. bool CheckNodeValid(const EdgePulse* edge)
  29. {
  30. if (edge == nullptr)
  31. {
  32. return false;
  33. }
  34. return CheckNodeValid(edge[0]);
  35. }
  36. bool CheckNodeValid(const EdgePulse edge)
  37. {
  38. if (edge.start_index < 0 || edge.end_index < 0 || edge.end_index <= edge.start_index
  39. || edge.edge == Edge::NONE)
  40. {
  41. return false;
  42. }
  43. return true;
  44. }
  45. void ReversalLevel(Edge& edge)
  46. {
  47. if (edge == Edge::FALL)
  48. {
  49. edge = Edge::RISE;
  50. }
  51. else if (edge == Edge::RISE)
  52. {
  53. edge = Edge::FALL;
  54. }
  55. }
  56. void ReversalLevel(std::vector<EdgePulse>& edge_pulses)
  57. {
  58. for (int i = 0; i < static_cast<int>(edge_pulses.size()); i++)
  59. {
  60. ReversalLevel(edge_pulses[i].edge);
  61. }
  62. }
  63. }