123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- #ifndef GLOBALINFO_H
- #define GLOBALINFO_H
- #include <mutex>
- #include <vector>
- #include <QRect>
- #include <QColor>
- #include <QBrush>
- /* 示波器通道 */
- enum class OscChannel
- {
- CH_A = 0,
- CH_B,
- };
- /* 示波器通道耦合方式 */
- enum class OscChannelCoupling
- {
- AC = 0,
- DC,
- };
- /* 示波器采样率,目前就只要这些 */
- enum class OscSampleRate
- {
- SR_49KHZ = 0,
- SR_96KHZ,
- SR_781KHZ,
- SR_12_5MHZ,
- SR_100MHZ,
- };
- /* 示波器通道的输入档位 */
- enum class OscChannelRange
- {
- CR_100MV = 0,
- CR_250MV,
- CR_500MV,
- CR_1V,
- CR_2V5,
- CR_5V,
- CR_8V,
- };
- /* 触发方式 */
- enum class OscTriggerMode
- {
- TM_RISE = 0, /* 上升沿触发 */
- TM_DOWN, /* 下降沿触发 */
- TM_DOUBLE, /* 双边沿触发 */
- };
- /* 触发灵敏度 */
- enum class OscTriggerSensitivity
- {
- TS_LOW = 0, /* 低灵敏度 */
- TS_HIGH, /* 高灵敏度 */
- };
- /* 一个格子的时间刻度值单位 */
- enum class OscTimeGridValue
- {
- TGV_20NS = 20, /* 0.02us */
- TGV_50NS = 50, /* 0.05us */
- TGV_100NS = 100, /* 0.1us */
- TGV_200NS = 200, /* 0.2us */
- TGV_500NS = 500, /* 0.5us */
- TGV_1US = 1000, /* 1us */
- TGV_2US = 2000, /* 2us */
- TGV_5US = 5000, /* 5us */
- TGV_10US = 10000, /* 10us */
- TGV_20US = 20000, /* 20us */
- TGV_100US = 100000, /* 100us */
- };
- struct EyeDataT
- {
- bool isEyeData;
- unsigned char value;
- EyeDataT() : isEyeData(false), value(0) {}
- EyeDataT(bool isOpen, unsigned char val) : isEyeData(isOpen), value(val) {}
- EyeDataT& operator=(const EyeDataT& data)
- {
- isEyeData = data.isEyeData;
- value = data.value;
- return *this;
- }
- };
- /* 眼图数据点 */
- struct EyeDataSample
- {
- int x; /* X坐标? */
- int y; /* Y坐标? */
- double fCnt; /* 颜色深浅? */
- int Cnt; /* */
- unsigned char data;
- EyeDataSample() : x(0), y(0), fCnt(0.0), Cnt(0), data(0) {}
- EyeDataSample(int x, int y, double fCnt, int Cnt, unsigned char data)
- : x(x), y(y), fCnt(fCnt), Cnt(Cnt), data(data) {}
- EyeDataSample& operator=(const EyeDataSample& data)
- {
- x = data.x;
- y = data.y;
- fCnt = data.fCnt;
- Cnt = data.Cnt;
- this->data = data.data;
- return *this;
- }
- };
- /* 类型重命名 */
- using Vec2D = std::vector<std::vector<EyeDataSample>>;
- /**
- * @brief 眼图数据
- *
- */
- class EyeDataMatrix
- {
- public:
- EyeDataMatrix() : dataMatrix(1000, std::vector<EyeDataSample>(256)) {}
- ~EyeDataMatrix() {}
- Vec2D dataMatrix;
- // EyeDataSample dataMatrix[1000][256];
- std::mutex mutexEyeData;
-
- void initEyeData();
- void addData(int x, int y);
- void eyeStatisticalWeight();
- void eyeLessenTheBurden();
- std::shared_ptr<Vec2D> eyeZoomOut();
- private:
- double eyenWeightCoefficient = 0.99;
- bool eyeIsLessenTheBurden = true;
- double eyenWeightCoefficientMIN = 1E-06;
- };
- extern EyeDataMatrix g_eyeDataMatrix;
- /**
- * @brief 绘制到窗口的眼图数据
- * 总共有1000 * 245个数据点充满屏幕,每个数据点是个矩形
- * 每个数据点的颜色深浅由fCnt决定,该点的数据越多,像素颜色越深
- *
- */
- struct EyeMapDataSample
- {
- bool isDraw; /* 是否绘制 */
- int x;
- int y;
- int Count; /* 像素点的个数(颜色深度),这里限制为799,不知道为什么 */
- unsigned char data; /* 数据值 */
- QRect rect; /* 像素点的矩形区域 */
- // QColor color; /* 颜色 */
- QBrush brush; /* 颜色 */
- // EyeMapDataSample() : isDraw(false), x(0), y(0), Count(0), data(0), color(255, 255, 255) {}
- EyeMapDataSample() : isDraw(false), x(0), y(0), Count(0), data(0) {}
- EyeMapDataSample(EyeDataSample& data) : isDraw(false), x(data.x), y(data.y), Count(data.Cnt), data(data.data) {}
- EyeMapDataSample& operator=(const EyeMapDataSample& other) {
- x = other.x;
- y = other.y;
- Count = other.Count;
- isDraw = other.isDraw;
- rect = other.rect;
- data = other.data;
- brush = other.brush;
- return *this;
- }
- };
- using Vec2DMap = std::vector<std::vector<EyeMapDataSample>>;
- /**
- * @brief 眼图数据矩阵
- *
- */
- class EyeMapMatrix
- {
- public:
- EyeMapMatrix() : dataMatrix(1000, std::vector<EyeMapDataSample>(256)) {}
- ~EyeMapMatrix() {}
- Vec2DMap dataMatrix;
- std::mutex mutexEyeData;
- /* 初始化数据点 */
- void initEyeMapData(int width, int height);
- /* 拷贝数据到数组中 */
- void copyDataMatrix(Vec2D& data);
- /* 将Count数值与颜色对应 */
- void addColorBySample();
- };
- extern EyeMapMatrix g_eyeMapMatrix;
- #define OscParams OscilloscopeParameters::getInstance()
- /**
- * @brief 示波器全局设置,这是个单例类
- *
- */
- class OscilloscopeParameters
- {
- private:
- OscilloscopeParameters() {}
- OscilloscopeParameters(const OscilloscopeParameters&) = delete;
- OscilloscopeParameters& operator=(const OscilloscopeParameters&) = delete;
- public:
- ~OscilloscopeParameters() {}
- static OscilloscopeParameters& getInstance()
- {
- static OscilloscopeParameters instance;
- return instance;
- }
- /* 示波器相关参数 */
- // int OscCurrentTimeScale = 100; /* 时间尺度,不知道啥意思,可能和采样率有关 */
- // int OscOneGridTime = 1000; /* 每格子的时间(单位ns) */
- int TimeGridNum = 10; /* 10个时间格子 */
- int VolatileGridNum = 10; /* 10个电压格子 */
- int oneGridTime = 200; /* 一个时间格子的时间长度(单位ns) */
- double SampleIntervalTime = 0; /* 采样点之间的时间间隔,单位ns(采样率的倒数,设置采样率的时候会设置) */
- /* 其他参数 */
- const int dataNumPerPixar = 1; /* 这个是SetInfo的第一个参数,固定是1,在眼图中会使用 */
- /* 眼图参数 */
- int eyeMapWidth = 1000; /* 眼图x轴宽度(像素矩形的个数) */
- };
- #endif /* GLOBALINFO_H */
|