OscDataInfo.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #ifndef _OSCDATAINFO_H_
  2. #define _OSCDATAINFO_H_
  3. #include <mutex>
  4. #include <vector>
  5. #include <QRect>
  6. #include <QColor>
  7. #include <QBrush>
  8. #include <QMap>
  9. #include "GlobalInfo.h"
  10. class OneOscilloscopeData;
  11. struct EyeDataT
  12. {
  13. bool isEyeData;
  14. unsigned char value;
  15. EyeDataT() : isEyeData(false), value(0) {}
  16. EyeDataT(bool isOpen, unsigned char val) : isEyeData(isOpen), value(val) {}
  17. EyeDataT& operator=(const EyeDataT& data)
  18. {
  19. isEyeData = data.isEyeData;
  20. value = data.value;
  21. return *this;
  22. }
  23. };
  24. /* 眼图数据点 */
  25. struct EyeDataSample
  26. {
  27. int x; /* X坐标? */
  28. int y; /* Y坐标? */
  29. double fCnt; /* 颜色深浅? */
  30. int Cnt; /* */
  31. unsigned char data;
  32. EyeDataSample() : x(0), y(0), fCnt(0.0), Cnt(0), data(0) {}
  33. EyeDataSample(int x, int y, double fCnt, int Cnt, unsigned char data)
  34. : x(x), y(y), fCnt(fCnt), Cnt(Cnt), data(data) {}
  35. EyeDataSample& operator=(const EyeDataSample& data)
  36. {
  37. x = data.x;
  38. y = data.y;
  39. fCnt = data.fCnt;
  40. Cnt = data.Cnt;
  41. this->data = data.data;
  42. return *this;
  43. }
  44. };
  45. /* 类型重命名 */
  46. using Vec2D = std::vector<std::vector<EyeDataSample>>;
  47. /**
  48. * @brief 眼图数据
  49. *
  50. */
  51. class EyeDataMatrix
  52. {
  53. public:
  54. EyeDataMatrix() : dataMatrix(g_HorPixel, std::vector<EyeDataSample>(g_VerPixel)) {}
  55. ~EyeDataMatrix() {}
  56. Vec2D dataMatrix;
  57. // EyeDataSample dataMatrix[g_HorPixel][256];
  58. std::mutex mutexEyeData;
  59. void initEyeData();
  60. void addData(int x, int y);
  61. void eyeStatisticalWeight();
  62. void eyeLessenTheBurden();
  63. std::shared_ptr<Vec2D> eyeZoomOut();
  64. private:
  65. double eyenWeightCoefficient = 0.99;
  66. bool eyeIsLessenTheBurden = true;
  67. double eyenWeightCoefficientMIN = 1E-06;
  68. };
  69. // extern EyeDataMatrix g_eyeDataMatrix;
  70. /**
  71. * @brief 绘制到窗口的眼图数据
  72. * 总共有g_HorPixel * 245个数据点充满屏幕,每个数据点是个矩形
  73. * 每个数据点的颜色深浅由fCnt决定,该点的数据越多,像素颜色越深
  74. *
  75. */
  76. struct EyeMapDataSample
  77. {
  78. bool isDraw; /* 是否绘制 */
  79. int x;
  80. int y;
  81. int Count; /* 像素点的个数(颜色深度),这里限制为799,不知道为什么 */
  82. unsigned char data; /* 数据值 */
  83. QRect rect; /* 像素点的矩形区域 */
  84. // QColor color; /* 颜色 */
  85. QBrush brush; /* 颜色 */
  86. // EyeMapDataSample() : isDraw(false), x(0), y(0), Count(0), data(0), color(255, 255, 255) {}
  87. EyeMapDataSample() : isDraw(false), x(0), y(0), Count(0), data(0) {}
  88. EyeMapDataSample(EyeDataSample& data) : isDraw(false), x(data.x), y(data.y), Count(data.Cnt), data(data.data) {}
  89. EyeMapDataSample& operator=(const EyeMapDataSample& other) {
  90. x = other.x;
  91. y = other.y;
  92. Count = other.Count;
  93. isDraw = other.isDraw;
  94. rect = other.rect;
  95. data = other.data;
  96. brush = other.brush;
  97. return *this;
  98. }
  99. };
  100. using Vec2DMap = std::vector<std::vector<EyeMapDataSample>>;
  101. /**
  102. * @brief 眼图数据矩阵
  103. *
  104. */
  105. class EyeMapMatrix
  106. {
  107. public:
  108. EyeMapMatrix() : dataMatrix(g_HorPixel, std::vector<EyeMapDataSample>(g_VerPixel)) {}
  109. ~EyeMapMatrix() {}
  110. Vec2DMap dataMatrix;
  111. std::mutex mutexEyeData;
  112. /* 初始化数据点 */
  113. void initEyeMapData(int width, int height);
  114. /* 拷贝数据到数组中 */
  115. void copyDataMatrix(Vec2D& data);
  116. /* 将Count数值与颜色对应 */
  117. void addColorBySample();
  118. };
  119. // extern EyeMapMatrix g_eyeMapMatrix;
  120. #define OscParams OscilloscopeParameters::getInstance()
  121. /**
  122. * @brief 示波器全局设置,也包含这所有通道的数据指针
  123. * 单例模式
  124. *
  125. */
  126. class OscilloscopeParameters
  127. {
  128. private:
  129. OscilloscopeParameters() {}
  130. OscilloscopeParameters(const OscilloscopeParameters&) = delete;
  131. OscilloscopeParameters& operator=(const OscilloscopeParameters&) = delete;
  132. public:
  133. ~OscilloscopeParameters() {}
  134. static OscilloscopeParameters& getInstance()
  135. {
  136. static OscilloscopeParameters instance;
  137. return instance;
  138. }
  139. /* 示波器相关参数 */
  140. // int oneGridTime = 200; /* 一个时间格子的时间长度(单位ns) */
  141. // double SampleIntervalTime = 0; /* 采样点之间的时间间隔,单位ns(采样率的倒数,设置采样率的时候会设置) */
  142. /* 其他参数 */
  143. const int dataNumPerPixar = 1; /* 这个是SetInfo的第一个参数,固定是1,在眼图中会使用 */
  144. /* 眼图参数 */
  145. // int eyeMapWidth = g_HorPixel; /* 眼图x轴宽度(像素矩形的个数) */
  146. public:
  147. };
  148. /**
  149. * @brief 示波器全局数据
  150. *
  151. */
  152. #define GOscDataInfo OscilloscopeData::getInstance()
  153. class OscilloscopeData
  154. {
  155. OscilloscopeData() {}
  156. OscilloscopeData(const OscilloscopeData&) = delete;
  157. OscilloscopeData& operator=(const OscilloscopeData&) = delete;
  158. public:
  159. ~OscilloscopeData();
  160. static OscilloscopeData& getInstance()
  161. {
  162. static OscilloscopeData instance;
  163. return instance;
  164. }
  165. /* 初始化示波器参数 */
  166. void initOscData();
  167. /* 查找EyeDataMatrix */
  168. EyeDataMatrix* findEyeDataMatrix(OscChnNum channel);
  169. /* 查找EyeMapMatrix */
  170. EyeMapMatrix* findEyeMapMatrix(OscChnNum channel);
  171. /* 获取示波器列表 */
  172. QMap<int, OneOscilloscopeData*>& getOsc() { return mapOsc; }
  173. /* 根据通道号查找示波器 */
  174. OneOscilloscopeData* findOsc(OscChnNum oscNum);
  175. /* 根据通道号设置电压范围 */
  176. void setVoltageRange(OscChnNum oscNum, OscVoltageRange range);
  177. /* 根据通道号设置时间刻度值 */
  178. void setTimeGridValue(OscChnNum oscNum, OscTimeGridValue value);
  179. /* 清空数据矩阵 */
  180. void resetDataMatrix();
  181. /* 清空颜色矩阵 */
  182. void resetColorMatrix(int width, int height);
  183. /* 暂停所有的采集 */
  184. void stopAllCapture();
  185. /* 开启所有的采集 */
  186. void startAllCapture();
  187. private:
  188. /************ 数据相关 ************/
  189. /* 眼图数据矩阵 */
  190. QMap<OscChnNum, EyeDataMatrix*> mapEyeDataMatrix;
  191. /* 眼图颜色矩阵 */
  192. QMap<OscChnNum, EyeMapMatrix*> mapEyeMapMatrix;
  193. /* 示波器类指针,int是示波器编号 */
  194. QMap<int, OneOscilloscopeData*> mapOsc;
  195. };
  196. #endif /* _OSCDATAINFO_H_ */