OscData.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef _OscilloscopeData_H_
  2. #define _OscilloscopeData_H_
  3. #include <QObject>
  4. #include <QMap>
  5. #include "USBInterFace.h"
  6. #include "spdlog/spdlog.h"
  7. #include "GlobalInfo.h"
  8. #include "RingQueue/RingQueue.hpp"
  9. #define OscData OscilloscopeData::getInstance()
  10. class OscilloscopeData : public QObject
  11. {
  12. Q_OBJECT
  13. const uint32_t BUFFER_SIZE = 1024 * 128 ; /* 缓冲区大小,OSCA02的缓冲区应该是128KB的SRAM */
  14. private:
  15. OscilloscopeData();
  16. OscilloscopeData(const OscilloscopeData&) = delete;
  17. OscilloscopeData& operator=(const OscilloscopeData&) = delete;
  18. public:
  19. ~OscilloscopeData();
  20. static OscilloscopeData& getInstance()
  21. {
  22. static OscilloscopeData instance;
  23. return instance;
  24. }
  25. /* 初始化示波器 */
  26. void initOsc();
  27. /* 打开示波器 */
  28. bool openOSC();
  29. /* 关闭示波器 */
  30. void closeOSC();
  31. /* 示波器是否打开 */
  32. bool isOpen() { return m_isOpen; }
  33. /* 开始采集数据 */
  34. bool startCapture();
  35. /* 停止采集数据 */
  36. void stopCapture();
  37. /***** 设置示波器的功能命令 *****/
  38. /* 设置示波器的采样率 */
  39. void setSampleRate(OscSampleRate rate);
  40. /* 将示波器两个通道合并为一个通道 */
  41. void setChannelMerge(bool merge);
  42. /* 设置通道A输入量程 */
  43. void setChannelARange(OscChannelRange range);
  44. /* 设置通道B输入量程 */
  45. void setChannelBRange(OscChannelRange range);
  46. /* 设置通道耦合方式 */
  47. void setChannelCoupling(OscChannel channel, OscChannelCoupling coupling);
  48. /* 开启或关闭通道A触发 */
  49. void setChannelATrigger(bool enable);
  50. /* 开启外触发 */
  51. void setExternalTrigger(bool enable);
  52. /* 设置触发方式 */
  53. void setTriggerMode(OscTriggerMode mode);
  54. /* 设置触发电平 */
  55. void setTriggerLevel(unsigned char level);
  56. /* 设置触发灵敏度 */
  57. void setTriggerSensitivity(OscTriggerSensitivity sensitivity);
  58. /* 设置触发在缓冲区的哪个位置 */
  59. void setTriggerPosition(unsigned char lowByte, unsigned char highByte);
  60. /* 获取示波器不同档位下的零电压值 */
  61. void getZeroVoltage();
  62. /* 打印出零电压值 */
  63. void printZeroVoltage(OscChannel channel);
  64. /* 获取不同档位下电压校准系数 */
  65. void getVoltageCalibration();
  66. /* 打印出电压校准系数 */
  67. void printVoltageCalibration(OscChannel channel);
  68. private:
  69. /* 采集数据,这个是子线程 */
  70. void threadCaptureData();
  71. /* 处理数据线程 */
  72. void threadProcessData();
  73. private:
  74. std::shared_ptr<spdlog::logger> m_logger = nullptr;
  75. std::shared_ptr<USBInterface> m_usbInterface = nullptr;
  76. std::atomic_bool m_isOpen = false; /* 示波器是否打开 */
  77. std::atomic_bool m_runCapture = false; /* 采集数据的线程标志 */
  78. std::atomic_bool m_isRunCapture = false; /* 采集数据的线程运行标志,这个标志位作为线程运行的标志 */
  79. std::atomic_bool m_isCaptureData = false; /* 是否采集到数据 */
  80. std::mutex m_mutexCaptureData; /* 互斥锁,用于保护采集到的数据 */
  81. unsigned char* m_devBuffer = nullptr; /* 设备缓冲区指针,拷贝数据用的 */
  82. unsigned char* m_buffer = nullptr; /* 缓冲区指针,用于存储拷贝出来的数据 */
  83. unsigned char* m_bufferChnA = nullptr; /* 通道A的缓冲区指针 */
  84. unsigned char* m_bufferChnB = nullptr; /* 通道B的缓冲区指针 */
  85. RingQueue<unsigned char*> m_ringQueue; /* 环形队列,用于存储示波器采集到的数据 */
  86. unsigned char m_ctrlByte0 = 0; /* 控制字节0 */
  87. unsigned char m_ctrlByte1 = 0; /* 控制字节1 */
  88. QMap<OscChannelRange, unsigned char> m_mapChAZeroVoltage; /* 通道A的零电压值 */
  89. QMap<OscChannelRange, unsigned char> m_mapChBZeroVoltage; /* 通道B的零电压值 */
  90. QMap<OscChannelRange, unsigned char> m_mapChAVoltageCalibration; /* 通道A的电压校准系数 */
  91. QMap<OscChannelRange, unsigned char> m_mapChBVoltageCalibration; /* 通道B的电压校准系数 */
  92. };
  93. #endif /* _OscilloscopeData_H_ */