123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #ifndef _OscilloscopeData_H_
- #define _OscilloscopeData_H_
- #include <QObject>
- #include <QMap>
- #include "USBInterFace.h"
- #include "spdlog/spdlog.h"
- #include "GlobalInfo.h"
- #include "RingQueue/RingQueue.hpp"
- #define OscData OscilloscopeData::getInstance()
- class OscilloscopeData : public QObject
- {
- Q_OBJECT
- const uint32_t BUFFER_SIZE = 1024 * 128 ; /* 缓冲区大小,OSCA02的缓冲区应该是128KB的SRAM */
- private:
- OscilloscopeData();
- OscilloscopeData(const OscilloscopeData&) = delete;
- OscilloscopeData& operator=(const OscilloscopeData&) = delete;
- public:
- ~OscilloscopeData();
- static OscilloscopeData& getInstance()
- {
- static OscilloscopeData instance;
- return instance;
- }
- /* 初始化示波器 */
- void initOsc();
- /* 打开示波器 */
- bool openOSC();
- /* 关闭示波器 */
- void closeOSC();
- /* 示波器是否打开 */
- bool isOpen() { return m_isOpen; }
- /* 开始采集数据 */
- bool startCapture();
- /* 停止采集数据 */
- void stopCapture();
- /***** 设置示波器的功能命令 *****/
- /* 设置示波器的采样率 */
- void setSampleRate(OscSampleRate rate);
- /* 将示波器两个通道合并为一个通道 */
- void setChannelMerge(bool merge);
- /* 设置通道A输入量程 */
- void setChannelARange(OscChannelRange range);
- /* 设置通道B输入量程 */
- void setChannelBRange(OscChannelRange range);
- /* 设置通道耦合方式 */
- void setChannelCoupling(OscChannel channel, OscChannelCoupling coupling);
- /* 开启或关闭通道A触发 */
- void setChannelATrigger(bool enable);
- /* 开启外触发 */
- void setExternalTrigger(bool enable);
- /* 设置触发方式 */
- void setTriggerMode(OscTriggerMode mode);
- /* 设置触发电平 */
- void setTriggerLevel(unsigned char level);
- /* 设置触发灵敏度 */
- void setTriggerSensitivity(OscTriggerSensitivity sensitivity);
- /* 设置触发在缓冲区的哪个位置 */
- void setTriggerPosition(unsigned char lowByte, unsigned char highByte);
- /* 获取示波器不同档位下的零电压值 */
- void getZeroVoltage();
- /* 打印出零电压值 */
- void printZeroVoltage(OscChannel channel);
- /* 获取不同档位下电压校准系数 */
- void getVoltageCalibration();
- /* 打印出电压校准系数 */
- void printVoltageCalibration(OscChannel channel);
- private:
- /* 采集数据,这个是子线程 */
- void threadCaptureData();
- /* 处理数据线程 */
- void threadProcessData();
- private:
- std::shared_ptr<spdlog::logger> m_logger = nullptr;
- std::shared_ptr<USBInterface> m_usbInterface = nullptr;
- std::atomic_bool m_isOpen = false; /* 示波器是否打开 */
- std::atomic_bool m_runCapture = false; /* 采集数据的线程标志 */
- std::atomic_bool m_isRunCapture = false; /* 采集数据的线程运行标志,这个标志位作为线程运行的标志 */
- std::atomic_bool m_isCaptureData = false; /* 是否采集到数据 */
- std::mutex m_mutexCaptureData; /* 互斥锁,用于保护采集到的数据 */
- unsigned char* m_devBuffer = nullptr; /* 设备缓冲区指针,拷贝数据用的 */
- unsigned char* m_buffer = nullptr; /* 缓冲区指针,用于存储拷贝出来的数据 */
- unsigned char* m_bufferChnA = nullptr; /* 通道A的缓冲区指针 */
- unsigned char* m_bufferChnB = nullptr; /* 通道B的缓冲区指针 */
- RingQueue<unsigned char*> m_ringQueue; /* 环形队列,用于存储示波器采集到的数据 */
- unsigned char m_ctrlByte0 = 0; /* 控制字节0 */
- unsigned char m_ctrlByte1 = 0; /* 控制字节1 */
- QMap<OscChannelRange, unsigned char> m_mapChAZeroVoltage; /* 通道A的零电压值 */
- QMap<OscChannelRange, unsigned char> m_mapChBZeroVoltage; /* 通道B的零电压值 */
- QMap<OscChannelRange, unsigned char> m_mapChAVoltageCalibration; /* 通道A的电压校准系数 */
- QMap<OscChannelRange, unsigned char> m_mapChBVoltageCalibration; /* 通道B的电压校准系数 */
- };
- #endif /* _OscilloscopeData_H_ */
|