USBDecode.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // // ******************************************************************
  2. // // /\ /| @File USBDecode.h
  3. // // \ V/ @Brief
  4. // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
  5. // // / | @Creation 2024-1-4
  6. // // / \\ @Modified 2024-1-15
  7. // // *(__\_\
  8. // // ******************************************************************
  9. #pragma once
  10. #include <iostream>
  11. #include <future>
  12. #include <chrono>
  13. #include <thread>
  14. #include <cmath>
  15. #include "../EdgePulse.h"
  16. #include "SYNC.h"
  17. #include "ProtocolUSBEnums.h"
  18. #include "USBDecodeOptions.h"
  19. #include "USBDecodeResult.h"
  20. #include "USBPacket.h"
  21. namespace Protocol
  22. {
  23. class USBDecode
  24. {
  25. public:
  26. USBDecode(): signalRate(), byteCount(0)
  27. {
  28. }
  29. double GetBitRateByPs() const;
  30. std::vector<std::string> EventInfoTitles() const;
  31. Enums::SignalRate SignalRate() const;
  32. void SetSignalRate(Enums::SignalRate value);
  33. uint16_t ByteCount() const;
  34. void SetByteCount(uint16_t value);
  35. static uint16_t MaxByteCount();
  36. static uint16_t MinByteCount();
  37. bool Parse_USB(UsbDecodeOptions option,std::vector<Protocol::TwoLevelEdgePulse> edgePluses1,
  38. std::vector<Protocol::TwoLevelEdgePulse> edgePluses2,std::promise<void>& cancellationSignal);
  39. private:
  40. UsbDecodeResult resultData;
  41. Enums::SignalRate signalRate;
  42. uint16_t byteCount;
  43. std::vector<USBPacket> usbPackets;
  44. private:
  45. bool CheckDifferenceWithinThreshold(double* array, int32_t size, double threshold = 0.15);
  46. void ClearEdgeArray(Protocol::Edge* edges, int32_t size);
  47. bool CheckSyncEdges(Protocol::Edge startEdge, Protocol::Edge* edges);
  48. bool CheckSyncSpans(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize, int32_t count,
  49. int32_t& avgSpans);
  50. bool CheckSyncSpansByArrary(int32_t* startIndexs, const int32_t count, int32_t& avgSpans);
  51. bool FindAllSyncs(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize,
  52. std::vector<SYNC>& allSYNC, std::promise<void>& cancellationSignal, bool polarity = false);
  53. bool FindPackets(Protocol::TwoLevelEdgePulse* node, int32_t& leftOverSize,
  54. std::vector<USBPacket>& allPacket, std::promise<void>& cancellationSignal,
  55. bool polarity = false);
  56. bool ParseData(std::vector<Protocol::TwoLevelEdgePulse> edgePluses,
  57. std::promise<void>& cancellationSignal);
  58. };
  59. }