feat: AiAnalysis - 16通道AI数据UDP实时采集与分析

功能:
- UDP端口监听,实时接收数据
- 解析16通道逗号分隔的ADC数据
- 实时波形绘制(支持滚轮缩放、右键拖拽、双击恢复)
- 数据自动保存到 data_端口号/ 目录
- 支持打开历史CSV文件回放查看
- 16通道独立颜色,可切换显示/隐藏
- 深色主题界面
This commit is contained in:
iorebuild
2026-04-30 12:46:49 +08:00
commit 7e3593c898
11 changed files with 1232 additions and 0 deletions

89
plotwidget.h Normal file
View File

@@ -0,0 +1,89 @@
#ifndef PLOTWIDGET_H
#define PLOTWIDGET_H
#include <QWidget>
#include <QVector>
#include <QColor>
#include <QTimer>
#include <QMouseEvent>
#include <QWheelEvent>
class PlotWidget : public QWidget
{
Q_OBJECT
public:
explicit PlotWidget(QWidget *parent = nullptr);
void addDataPoint(const QVector<double> &values);
void setAllData(const QVector<QVector<double>> &channels);
void clear();
void setChannelVisible(int channel, bool visible);
bool isChannelVisible(int channel) const;
void setDisplayPointCount(int count);
int displayPointCount() const;
void setYRange(double min, double max);
void autoRangeY();
void setTitle(const QString &title);
int totalPoints() const;
protected:
void paintEvent(QPaintEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private:
void drawBackground(QPainter &painter);
void drawGrid(QPainter &painter);
void drawCurves(QPainter &painter);
void drawAxes(QPainter &painter);
void drawLegend(QPainter &painter);
QRectF plotArea() const;
QPointF dataToWidget(double x, double y) const;
static QList<QColor> defaultColors();
// 数据
QVector<QVector<double>> m_data; // 16个通道
QVector<bool> m_channelVisible;
int m_totalPoints;
// 视图参数
int m_displayPoints;
double m_yMin, m_yMax;
bool m_autoYRange;
bool m_autoScroll;
// 鼠标交互
bool m_dragging;
QPoint m_dragStart;
double m_dragYMinStart, m_dragYMaxStart;
// 边距
int m_marginLeft;
int m_marginRight;
int m_marginTop;
int m_marginBottom;
// 颜色
QList<QColor> m_colors;
QColor m_bgColor;
QColor m_gridColor;
QColor m_gridColorMinor;
QColor m_textColor;
QColor m_axisColor;
// 标题
QString m_title;
// 刷新定时器
QTimer *m_refreshTimer;
bool m_dirty;
};
#endif // PLOTWIDGET_H