添加测量工作类
This commit is contained in:
parent
d5caa22930
commit
3c72ba9654
|
|
@ -156,22 +156,25 @@ void MainWindow::initAction()
|
|||
if (QDialog::Accepted == new_measure_analysis_dlg.exec()) {
|
||||
ProjectList* project_list_model = ProjectList::Instance();
|
||||
auto project_model = project_list_model->GetCurrentProjectModel();
|
||||
|
||||
emit newProject(project_model->GetProjectName());
|
||||
|
||||
const QString& all_channel_particle_data_filename = project_model->GetAllChannelParticleDataFilename();
|
||||
if (!all_channel_particle_data_filename.isEmpty()) {
|
||||
const QString& all_ch_count_dir = project_model->GetProjectDir();
|
||||
const QString& every_ch_count_dir = QDir(project_model->GetProjectDir()).filePath(QStringLiteral(u"通道道址计数"));
|
||||
auto count_task = new DataProcessWorkPool::EveryChannelParticleCountDataTask;
|
||||
count_task->SetAllChannelParticleDataFilename(all_channel_particle_data_filename);
|
||||
count_task->SetAllChannelCountResultDir(all_ch_count_dir);
|
||||
count_task->SetEveryChannelCountResultDir(every_ch_count_dir);
|
||||
count_task->SetFinishedNotifier(project_list_model, "onChannelAddressCountProcessFinished", project_model->GetProjectName());
|
||||
count_task->StartTask();
|
||||
auto coincidence_process_task = new DataProcessWorkPool::CoincidenceEventAnalysisTask;
|
||||
coincidence_process_task->SetFinishedNotifier(project_list_model, "onCoincidenceProcessFinished", project_model->GetProjectName());
|
||||
coincidence_process_task->StartTask();
|
||||
if (project_model->GetIsMeasureComplete()) {
|
||||
const QString& all_channel_particle_data_filename = project_model->GetAllChannelParticleDataFilename();
|
||||
if (!all_channel_particle_data_filename.isEmpty()) {
|
||||
const QString& all_ch_count_dir = project_model->GetProjectDir();
|
||||
const QString& every_ch_count_dir = QDir(project_model->GetProjectDir()).filePath(QStringLiteral(u"通道道址计数"));
|
||||
auto count_task = new DataProcessWorkPool::EveryChannelParticleCountDataTask;
|
||||
count_task->SetAllChannelParticleDataFilename(all_channel_particle_data_filename);
|
||||
count_task->SetAllChannelCountResultDir(all_ch_count_dir);
|
||||
count_task->SetEveryChannelCountResultDir(every_ch_count_dir);
|
||||
count_task->SetFinishedNotifier(project_list_model, "onChannelAddressCountProcessFinished", project_model->GetProjectName());
|
||||
count_task->StartTask();
|
||||
auto coincidence_process_task = new DataProcessWorkPool::CoincidenceEventAnalysisTask;
|
||||
coincidence_process_task->SetFinishedNotifier(project_list_model, "onCoincidenceProcessFinished", project_model->GetProjectName());
|
||||
coincidence_process_task->StartTask();
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -264,6 +264,46 @@ const QString MeasureAnalysisProjectModel::GetAnalysisCustomData(AnalysisType an
|
|||
return this->_analysis_custom_data_set.value(analysis_type).value(data_item_name);
|
||||
}
|
||||
|
||||
void MeasureAnalysisProjectModel::SetDeviceGuid(const QString &device_guid)
|
||||
{
|
||||
this->_device_guid = device_guid;
|
||||
}
|
||||
|
||||
const QString &MeasureAnalysisProjectModel::GetDeviceGuid() const
|
||||
{
|
||||
return this->_device_guid;
|
||||
}
|
||||
|
||||
void MeasureAnalysisProjectModel::SetStartTime(const QString &start_time)
|
||||
{
|
||||
this->_start_time = start_time;
|
||||
}
|
||||
|
||||
const QString &MeasureAnalysisProjectModel::GetStartTime() const
|
||||
{
|
||||
return this->_start_time;
|
||||
}
|
||||
|
||||
void MeasureAnalysisProjectModel::SetEndTime(const QString &end_time)
|
||||
{
|
||||
this->_end_time = end_time;
|
||||
}
|
||||
|
||||
const QString &MeasureAnalysisProjectModel::GetEndTime() const
|
||||
{
|
||||
return this->_end_time;
|
||||
}
|
||||
|
||||
void MeasureAnalysisProjectModel::SetGvfFilename(const QString &gvf_filename)
|
||||
{
|
||||
this->_gvf_filename = gvf_filename;
|
||||
}
|
||||
|
||||
const QString &MeasureAnalysisProjectModel::GetGvfFilename() const
|
||||
{
|
||||
return this->_gvf_filename;
|
||||
}
|
||||
|
||||
bool MeasureAnalysisProjectModel::LoadProjectModel(const QString& project_filename)
|
||||
{
|
||||
QVariantMap model_data;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,15 @@ public:
|
|||
const QMap<uint, QString> GetTimeWinConformEnergyDataFilenameList(uint time_win) const;
|
||||
const QString GetAnalysisCustomData(AnalysisType analysis_type, const QString& data_item_name);
|
||||
|
||||
void SetDeviceGuid(const QString& device_guid);
|
||||
const QString& GetDeviceGuid() const;
|
||||
void SetStartTime(const QString& start_time);
|
||||
const QString& GetStartTime() const;
|
||||
void SetEndTime(const QString& end_time);
|
||||
const QString& GetEndTime() const;
|
||||
void SetGvfFilename(const QString& gvf_filename);
|
||||
const QString& GetGvfFilename() const;
|
||||
|
||||
private:
|
||||
QString _project_dir;
|
||||
QString _project_name;
|
||||
|
|
@ -89,6 +98,11 @@ private:
|
|||
QMap<uint, QMap<uint, QString> > _time_win_conform_energy_data;
|
||||
QMap<AnalysisType, QMap<QString, QString> > _analysis_custom_data_set;
|
||||
|
||||
QString _device_guid;
|
||||
QString _gvf_filename;
|
||||
QString _start_time;
|
||||
QString _end_time;
|
||||
|
||||
public:
|
||||
bool LoadProjectModel(const QString& project_filename);
|
||||
bool SaveProjectModel();
|
||||
|
|
|
|||
60
src/MeasureClient/MeasureClient.h
Normal file
60
src/MeasureClient/MeasureClient.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef MEASURECLIENT_H
|
||||
#define MEASURECLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
#include <QDataStream>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QVariantMap>
|
||||
#include <QVariantList>
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
|
||||
class MeasureClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MeasureClient(QObject *parent = nullptr);
|
||||
~MeasureClient();
|
||||
|
||||
// 设置服务器地址和端口
|
||||
void setServerAddress(const QString &host, quint16 port);
|
||||
// 启动测量(异步)
|
||||
void startMeasure(const QString &deviceGuid, const QVariantMap &config);
|
||||
// 停止测量(异步)
|
||||
void stopMeasure(const QString &deviceGuid);
|
||||
// 设置测量参数(异步)
|
||||
void setMeasureConfigParams(const QString &deviceGuid, const QVariantMap &config);
|
||||
// 清除数据(异步)
|
||||
void clearData(const QString &deviceGuid);
|
||||
// 获取设备列表(异步)
|
||||
void getDeviceList();
|
||||
|
||||
signals:
|
||||
// 操作结果信号
|
||||
void startMeasureResult(bool success, const QString &info);
|
||||
void stopMeasureResult(bool success, const QString &message);
|
||||
void setMeasureConfigParamsResult(bool success, const QString &message);
|
||||
void clearDataResult(bool success, const QString &message);
|
||||
void getDeviceListResult(bool success, const QStringList &devices);
|
||||
// 错误信号
|
||||
void errorOccurred(const QString &errorString);
|
||||
|
||||
private slots:
|
||||
// 处理命令执行
|
||||
void processCommand(const QString &command, const QString &device_guid, const QVariantMap &config);
|
||||
|
||||
private:
|
||||
// 发送命令并获取响应(短连接模式)
|
||||
QVariantMap sendCommand(const QString &command, const QString &device_guid, const QString &data = QString());
|
||||
|
||||
private:
|
||||
QString _host;
|
||||
quint16 _port;
|
||||
QThread *_workerThread;
|
||||
QMutex _mutex;
|
||||
};
|
||||
|
||||
#endif // MEASURECLIENT_H
|
||||
|
|
@ -2,7 +2,9 @@ INCLUDEPATH += $${PWD}
|
|||
DEPENDPATH += $${PWD}
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/MeasureClient.cpp
|
||||
$$PWD/MeasureClient.cpp \
|
||||
$$PWD/MeasureWorker.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/MeasureClient.h
|
||||
$$PWD/MeasureClient.h \
|
||||
$$PWD/MeasureWorker.h
|
||||
165
src/MeasureClient/MeasureWorker.cpp
Normal file
165
src/MeasureClient/MeasureWorker.cpp
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
#include "MeasureWorker.h"
|
||||
#include "MeasureClient.h"
|
||||
#include <QDir>
|
||||
#include "GlobalDefine.h"
|
||||
#include "MeasureAnalysisProjectModel.h"
|
||||
|
||||
MeasureWorker* MeasureWorker::_s_instance { nullptr };
|
||||
|
||||
MeasureWorker::MeasureWorker(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
_measure_client = new MeasureClient;
|
||||
connect(_measure_client, &MeasureClient::getDeviceListResult, this, &MeasureWorker::onGetDeviceListResult);
|
||||
connect(_measure_client, &MeasureClient::startMeasureResult, this, &MeasureWorker::onStartMeasureResult);
|
||||
connect(_measure_client, &MeasureClient::stopMeasureResult, this, &MeasureWorker::onStopMeasureResult);
|
||||
connect(_measure_client, &MeasureClient::setMeasureConfigParamsResult, this, &MeasureWorker::onSetMeasureConfigParamsResult);
|
||||
connect(_measure_client, &MeasureClient::clearDataResult, this, &MeasureWorker::onClearDataResult);
|
||||
connect(_measure_client, &MeasureClient::errorOccurred, this, &MeasureWorker::onErrorOccurred);
|
||||
}
|
||||
|
||||
MeasureWorker *MeasureWorker::Instance()
|
||||
{
|
||||
if (!_s_instance) {
|
||||
_s_instance = new MeasureWorker();
|
||||
}
|
||||
return _s_instance;
|
||||
}
|
||||
|
||||
MeasureWorker::~MeasureWorker()
|
||||
{
|
||||
delete _measure_client;
|
||||
}
|
||||
|
||||
void MeasureWorker::SetMeasureProjectName(const QString &project_name)
|
||||
{
|
||||
_measure_project_name = project_name;
|
||||
}
|
||||
|
||||
void MeasureWorker::Connect()
|
||||
{
|
||||
LOG_INFO(QStringLiteral(u"查找测量设备... ..."));
|
||||
_measure_client->getDeviceList();
|
||||
}
|
||||
|
||||
void MeasureWorker::Start()
|
||||
{
|
||||
auto project_model = ProjectList::Instance()->GetProjectModel(_measure_project_name);
|
||||
if (!project_model) {
|
||||
return;
|
||||
}
|
||||
const QString& device_guid = project_model->GetDeviceGuid();
|
||||
if (device_guid.isEmpty()) {
|
||||
LOG_WARN(QStringLiteral(u"未选择测量设备GUID."));
|
||||
return;
|
||||
}
|
||||
const QString& config_filename = project_model->GetMeasureDeviceParamsCfgFilename();
|
||||
QFile json_file(config_filename);
|
||||
if (!json_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
LOG_WARN(QStringLiteral(u"加载设备参数配置失败:%1").arg(config_filename));
|
||||
return;
|
||||
}
|
||||
QByteArray json_data = json_file.readAll();
|
||||
json_file.close();
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(json_data);
|
||||
if (json_doc.isNull()) {
|
||||
return;
|
||||
}
|
||||
if (!json_doc.isObject())
|
||||
return;
|
||||
QVariantMap device_config_info = json_doc.object().toVariantMap();
|
||||
if (!device_config_info.contains(QStringLiteral(u"ChannelConfig")))
|
||||
return;
|
||||
QVariantList channel_config_list = device_config_info[QStringLiteral(u"ChannelConfig")].toList();
|
||||
if (channel_config_list.isEmpty()) {
|
||||
LOG_WARN(QStringLiteral(u"测量设备通道配置参数为空."));
|
||||
return;
|
||||
}
|
||||
LOG_INFO(QStringLiteral(u"开始测量... ..."));
|
||||
_measure_client->startMeasure(device_guid, device_config_info);
|
||||
}
|
||||
|
||||
void MeasureWorker::Stop()
|
||||
{
|
||||
auto project_model = ProjectList::Instance()->GetProjectModel(_measure_project_name);
|
||||
if (!project_model) {
|
||||
return;
|
||||
}
|
||||
const QString& device_guid = project_model->GetDeviceGuid();
|
||||
if (device_guid.isEmpty()) {
|
||||
LOG_WARN(QStringLiteral(u"未选择测量设备GUID."));
|
||||
return;
|
||||
}
|
||||
LOG_INFO(QStringLiteral(u"停止测量... ..."));
|
||||
_measure_client->stopMeasure(device_guid);
|
||||
}
|
||||
|
||||
void MeasureWorker::ClearData()
|
||||
{
|
||||
auto project_model = ProjectList::Instance()->GetProjectModel(_measure_project_name);
|
||||
if (!project_model) {
|
||||
return;
|
||||
}
|
||||
const QString& device_guid = project_model->GetDeviceGuid();
|
||||
if (device_guid.isEmpty()) {
|
||||
LOG_WARN(QStringLiteral(u"未选择测量设备GUID."));
|
||||
return;
|
||||
}
|
||||
LOG_INFO(QStringLiteral(u"清除测量数据... ..."));
|
||||
_measure_client->clearData(device_guid);
|
||||
}
|
||||
|
||||
void MeasureWorker::onStartMeasureResult(bool success, const QString &info)
|
||||
{
|
||||
if (success) {
|
||||
LOG_INFO(QStringLiteral(u"启动测量成功"));
|
||||
LOG_INFO(QStringLiteral(u"测量数据GVF文件: %1").arg(info));
|
||||
} else {
|
||||
LOG_WARN(QStringLiteral(u"启动测量失败: %1").arg(info));
|
||||
}
|
||||
}
|
||||
|
||||
void MeasureWorker::onStopMeasureResult(bool success, const QString &message)
|
||||
{
|
||||
if (success) {
|
||||
LOG_INFO(QStringLiteral(u"停止测量成功"));
|
||||
} else {
|
||||
LOG_WARN(QStringLiteral(u"停止测量失败: %1").arg(message));
|
||||
}
|
||||
}
|
||||
|
||||
void MeasureWorker::onSetMeasureConfigParamsResult(bool success, const QString &message)
|
||||
{
|
||||
if (success) {
|
||||
LOG_INFO(QStringLiteral(u"设置测量参数成功"));
|
||||
} else {
|
||||
LOG_WARN(QStringLiteral(u"设置测量参数失败: %1").arg(message));
|
||||
}
|
||||
}
|
||||
|
||||
void MeasureWorker::onClearDataResult(bool success, const QString &message)
|
||||
{
|
||||
if (success) {
|
||||
LOG_INFO(QStringLiteral(u"清除测量数据成功"));
|
||||
} else {
|
||||
LOG_WARN(QStringLiteral(u"清除测量数据失败: %1").arg(message));
|
||||
}
|
||||
}
|
||||
|
||||
void MeasureWorker::onGetDeviceListResult(bool success, const QStringList &devices)
|
||||
{
|
||||
if (success && !devices.isEmpty()) {
|
||||
LOG_INFO(QStringLiteral(u"获取测量设备GUID成功:%1").arg(devices.first()));
|
||||
auto project_model = ProjectList::Instance()->GetProjectModel(_measure_project_name);
|
||||
if (project_model) {
|
||||
project_model->SetDeviceGuid(devices.first());
|
||||
}
|
||||
} else {
|
||||
LOG_WARN(QStringLiteral(u"获取测量设备失败"));
|
||||
}
|
||||
}
|
||||
|
||||
void MeasureWorker::onErrorOccurred(const QString &errorString)
|
||||
{
|
||||
LOG_WARN(QStringLiteral(u"错误: %1").arg(errorString));
|
||||
}
|
||||
42
src/MeasureClient/MeasureWorker.h
Normal file
42
src/MeasureClient/MeasureWorker.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef MEASUREWORKER_H
|
||||
#define MEASUREWORKER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class MeasureClient;
|
||||
|
||||
class MeasureWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
private:
|
||||
MeasureWorker(QObject* parent = nullptr);
|
||||
static MeasureWorker* _s_instance;
|
||||
|
||||
public:
|
||||
static MeasureWorker* Instance();
|
||||
virtual ~MeasureWorker();
|
||||
|
||||
void SetMeasureProjectName(const QString& project_name);
|
||||
|
||||
void Connect();
|
||||
void Start();
|
||||
void Stop();
|
||||
void ClearData();
|
||||
|
||||
private slots:
|
||||
void onStartMeasureResult(bool success, const QString& info);
|
||||
void onStopMeasureResult(bool success, const QString& message);
|
||||
void onSetMeasureConfigParamsResult(bool success, const QString& message);
|
||||
void onClearDataResult(bool success, const QString& message);
|
||||
void onGetDeviceListResult(bool success, const QStringList &devices);
|
||||
void onErrorOccurred(const QString &errorString);
|
||||
|
||||
private:
|
||||
MeasureClient* _measure_client = nullptr;
|
||||
QString _measure_project_name;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ void NewMeasureAnalysisDlg::newProject(const QString& particle_data_filename)
|
|||
} else if (ui->rbtn_background_spec->isChecked()) {
|
||||
spec_type = MeasureAnalysisProjectModel::SpectrumType::Background;
|
||||
}
|
||||
bool is_measure_complete = true;
|
||||
bool is_measure_complete = !particle_data_filename.isEmpty();
|
||||
MeasureAnalysisProjectModel* model = new MeasureAnalysisProjectModel;
|
||||
model->SetProjectDir(project_dir_path);
|
||||
model->SetProjectName(project_name);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user