OscDataInfo.h 6.7 KB

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