GlobalInfo.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #ifndef GLOBALINFO_H
  2. #define GLOBALINFO_H
  3. #include <mutex>
  4. #include <vector>
  5. #include <QRect>
  6. #include <QColor>
  7. #include <QBrush>
  8. /* 示波器通道 */
  9. enum class OscChannel
  10. {
  11. CH_A = 0,
  12. CH_B,
  13. };
  14. /* 示波器通道耦合方式 */
  15. enum class OscChannelCoupling
  16. {
  17. AC = 0,
  18. DC,
  19. };
  20. /* 示波器采样率,目前就只要这些 */
  21. enum class OscSampleRate
  22. {
  23. SR_49KHZ = 0,
  24. SR_96KHZ,
  25. SR_781KHZ,
  26. SR_12_5MHZ,
  27. SR_100MHZ,
  28. };
  29. /* 示波器通道的输入档位 */
  30. enum class OscChannelRange
  31. {
  32. CR_100MV = 0,
  33. CR_250MV,
  34. CR_500MV,
  35. CR_1V,
  36. CR_2V5,
  37. CR_5V,
  38. CR_8V,
  39. };
  40. /* 触发方式 */
  41. enum class OscTriggerMode
  42. {
  43. TM_RISE = 0, /* 上升沿触发 */
  44. TM_DOWN, /* 下降沿触发 */
  45. TM_DOUBLE, /* 双边沿触发 */
  46. };
  47. /* 触发灵敏度 */
  48. enum class OscTriggerSensitivity
  49. {
  50. TS_LOW = 0, /* 低灵敏度 */
  51. TS_HIGH, /* 高灵敏度 */
  52. };
  53. /* 一个格子的时间刻度值单位 */
  54. enum class OscTimeGridValue
  55. {
  56. TGV_20NS = 20, /* 0.02us */
  57. TGV_50NS = 50, /* 0.05us */
  58. TGV_100NS = 100, /* 0.1us */
  59. TGV_200NS = 200, /* 0.2us */
  60. TGV_500NS = 500, /* 0.5us */
  61. TGV_1US = 1000, /* 1us */
  62. TGV_2US = 2000, /* 2us */
  63. TGV_5US = 5000, /* 5us */
  64. TGV_10US = 10000, /* 10us */
  65. TGV_20US = 20000, /* 20us */
  66. TGV_100US = 100000, /* 100us */
  67. };
  68. struct EyeDataT
  69. {
  70. bool isEyeData;
  71. unsigned char value;
  72. EyeDataT() : isEyeData(false), value(0) {}
  73. EyeDataT(bool isOpen, unsigned char val) : isEyeData(isOpen), value(val) {}
  74. EyeDataT& operator=(const EyeDataT& data)
  75. {
  76. isEyeData = data.isEyeData;
  77. value = data.value;
  78. return *this;
  79. }
  80. };
  81. /* 眼图数据点 */
  82. struct EyeDataSample
  83. {
  84. int x; /* X坐标? */
  85. int y; /* Y坐标? */
  86. double fCnt; /* 颜色深浅? */
  87. int Cnt; /* */
  88. unsigned char data;
  89. EyeDataSample() : x(0), y(0), fCnt(0.0), Cnt(0), data(0) {}
  90. EyeDataSample(int x, int y, double fCnt, int Cnt, unsigned char data)
  91. : x(x), y(y), fCnt(fCnt), Cnt(Cnt), data(data) {}
  92. EyeDataSample& operator=(const EyeDataSample& data)
  93. {
  94. x = data.x;
  95. y = data.y;
  96. fCnt = data.fCnt;
  97. Cnt = data.Cnt;
  98. this->data = data.data;
  99. return *this;
  100. }
  101. };
  102. /* 类型重命名 */
  103. using Vec2D = std::vector<std::vector<EyeDataSample>>;
  104. /**
  105. * @brief 眼图数据
  106. *
  107. */
  108. class EyeDataMatrix
  109. {
  110. public:
  111. EyeDataMatrix() : dataMatrix(1000, std::vector<EyeDataSample>(256)) {}
  112. ~EyeDataMatrix() {}
  113. Vec2D dataMatrix;
  114. // EyeDataSample dataMatrix[1000][256];
  115. std::mutex mutexEyeData;
  116. void initEyeData();
  117. void addData(int x, int y);
  118. void eyeStatisticalWeight();
  119. void eyeLessenTheBurden();
  120. std::shared_ptr<Vec2D> eyeZoomOut();
  121. private:
  122. double eyenWeightCoefficient = 0.99;
  123. bool eyeIsLessenTheBurden = true;
  124. double eyenWeightCoefficientMIN = 1E-06;
  125. };
  126. extern EyeDataMatrix g_eyeDataMatrix;
  127. /**
  128. * @brief 绘制到窗口的眼图数据
  129. * 总共有1000 * 245个数据点充满屏幕,每个数据点是个矩形
  130. * 每个数据点的颜色深浅由fCnt决定,该点的数据越多,像素颜色越深
  131. *
  132. */
  133. struct EyeMapDataSample
  134. {
  135. bool isDraw; /* 是否绘制 */
  136. int x;
  137. int y;
  138. int Count; /* 像素点的个数(颜色深度),这里限制为799,不知道为什么 */
  139. unsigned char data; /* 数据值 */
  140. QRect rect; /* 像素点的矩形区域 */
  141. // QColor color; /* 颜色 */
  142. QBrush brush; /* 颜色 */
  143. // EyeMapDataSample() : isDraw(false), x(0), y(0), Count(0), data(0), color(255, 255, 255) {}
  144. EyeMapDataSample() : isDraw(false), x(0), y(0), Count(0), data(0) {}
  145. EyeMapDataSample(EyeDataSample& data) : isDraw(false), x(data.x), y(data.y), Count(data.Cnt), data(data.data) {}
  146. EyeMapDataSample& operator=(const EyeMapDataSample& other) {
  147. x = other.x;
  148. y = other.y;
  149. Count = other.Count;
  150. isDraw = other.isDraw;
  151. rect = other.rect;
  152. data = other.data;
  153. brush = other.brush;
  154. return *this;
  155. }
  156. };
  157. using Vec2DMap = std::vector<std::vector<EyeMapDataSample>>;
  158. /**
  159. * @brief 眼图数据矩阵
  160. *
  161. */
  162. class EyeMapMatrix
  163. {
  164. public:
  165. EyeMapMatrix() : dataMatrix(1000, std::vector<EyeMapDataSample>(256)) {}
  166. ~EyeMapMatrix() {}
  167. Vec2DMap dataMatrix;
  168. std::mutex mutexEyeData;
  169. /* 初始化数据点 */
  170. void initEyeMapData(int width, int height);
  171. /* 拷贝数据到数组中 */
  172. void copyDataMatrix(Vec2D& data);
  173. /* 将Count数值与颜色对应 */
  174. void addColorBySample();
  175. };
  176. extern EyeMapMatrix g_eyeMapMatrix;
  177. #define OscParams OscilloscopeParameters::getInstance()
  178. /**
  179. * @brief 示波器全局设置,这是个单例类
  180. *
  181. */
  182. class OscilloscopeParameters
  183. {
  184. private:
  185. OscilloscopeParameters() {}
  186. OscilloscopeParameters(const OscilloscopeParameters&) = delete;
  187. OscilloscopeParameters& operator=(const OscilloscopeParameters&) = delete;
  188. public:
  189. ~OscilloscopeParameters() {}
  190. static OscilloscopeParameters& getInstance()
  191. {
  192. static OscilloscopeParameters instance;
  193. return instance;
  194. }
  195. /* 示波器相关参数 */
  196. // int OscCurrentTimeScale = 100; /* 时间尺度,不知道啥意思,可能和采样率有关 */
  197. // int OscOneGridTime = 1000; /* 每格子的时间(单位ns) */
  198. int TimeGridNum = 10; /* 10个时间格子 */
  199. int VolatileGridNum = 10; /* 10个电压格子 */
  200. int oneGridTime = 200; /* 一个时间格子的时间长度(单位ns) */
  201. double SampleIntervalTime = 0; /* 采样点之间的时间间隔,单位ns(采样率的倒数,设置采样率的时候会设置) */
  202. /* 其他参数 */
  203. const int dataNumPerPixar = 1; /* 这个是SetInfo的第一个参数,固定是1,在眼图中会使用 */
  204. /* 眼图参数 */
  205. int eyeMapWidth = 1000; /* 眼图x轴宽度(像素矩形的个数) */
  206. };
  207. #endif /* GLOBALINFO_H */