first commit

This commit is contained in:
2026-01-02 19:20:35 +09:00
commit a10cb30c4a
94 changed files with 28609 additions and 0 deletions

349
hardware/channelmanager.cpp Normal file
View File

@@ -0,0 +1,349 @@
#include "channelmanager.h"
ChannelManager *ChannelManager::m_instance = nullptr;
ChannelManager::ChannelManager(QObject *parent) : QObject(parent)
{
initializeChannelCapabilities();
// Initialize all channels as available
for (int i = INPUT_CHANNEL_1; i <= OUTPUT_CHANNEL_2; ++i)
{
ChannelId channelId = static_cast<ChannelId>(i);
ChannelStatus status;
status.occupied = false;
status.operationDetails.operation = NONE;
status.operationDetails.description = QString();
status.operationDetails.connectionType = TWO_WIRE;
m_channelStatus[channelId] = status;
}
}
ChannelManager *ChannelManager::instance()
{
if (!m_instance)
{
m_instance = new ChannelManager();
}
return m_instance;
}
void ChannelManager::initializeChannelCapabilities()
{
// 输入通道1: 支持最多四线连接(白-红-灰-黑),可进行所有测量功能
ChannelCapability inputCh1;
inputCh1.type = INPUT_CHANNEL;
inputCh1.maxWires = 4;
inputCh1.wireColors = QStringList() << "" << "" << "" << "";
inputCh1.supportedConnections = QList<ConnectionType>()
<< TWO_WIRE << THREE_WIRE << FOUR_WIRE;
inputCh1.supportedOperations = QList<OperationType>()
<< VOLTAGE_MEASUREMENT << MV_MEASUREMENT
<< MA_MEASUREMENT << AC_MEASUREMENT
<< RESISTANCE_MEASUREMENT << FREQUENCY_MEASUREMENT
<< SWITCH_MEASUREMENT << INSULATION_MEASUREMENT;
m_channelCapabilities[INPUT_CHANNEL_1] = inputCh1;
// 输入通道2: 支持最多两线连接(白-灰),仅支持二线制测量
ChannelCapability inputCh2;
inputCh2.type = INPUT_CHANNEL;
inputCh2.maxWires = 2;
inputCh2.wireColors = QStringList() << "" << "";
inputCh2.supportedConnections = QList<ConnectionType>() << TWO_WIRE;
inputCh2.supportedOperations = QList<OperationType>()
<< VOLTAGE_MEASUREMENT << MV_MEASUREMENT
<< MA_MEASUREMENT << AC_MEASUREMENT
<< RESISTANCE_MEASUREMENT << FREQUENCY_MEASUREMENT
<< SWITCH_MEASUREMENT;
m_channelCapabilities[INPUT_CHANNEL_2] = inputCh2;
// 输出通道1: 支持最多四线连接(用于电阻模拟)
ChannelCapability outputCh1;
outputCh1.type = OUTPUT_CHANNEL;
outputCh1.maxWires = 4;
outputCh1.wireColors = QStringList() << "" << "" << "" << "";
outputCh1.supportedConnections = QList<ConnectionType>()
<< TWO_WIRE << THREE_WIRE << FOUR_WIRE;
outputCh1.supportedOperations = QList<OperationType>()
<< VOLTAGE_OUTPUT << MV_OUTPUT << MA_OUTPUT
<< WAVEFORM_OUTPUT << RESISTANCE_SIMULATION;
m_channelCapabilities[OUTPUT_CHANNEL_1] = outputCh1;
// 输出通道2: 支持两线连接
ChannelCapability outputCh2;
outputCh2.type = OUTPUT_CHANNEL;
outputCh2.maxWires = 2;
outputCh2.wireColors = QStringList() << "" << "";
outputCh2.supportedConnections = QList<ConnectionType>() << TWO_WIRE;
outputCh2.supportedOperations = QList<OperationType>()
<< VOLTAGE_OUTPUT << MV_OUTPUT << MA_OUTPUT
<< WAVEFORM_OUTPUT;
m_channelCapabilities[OUTPUT_CHANNEL_2] = outputCh2;
}
bool ChannelManager::isChannelAvailable(ChannelId channel) const
{
return !m_channelStatus.value(channel).occupied;
}
bool ChannelManager::canChannelSupport(ChannelId channel, OperationType operation,
ConnectionType connection) const
{
if (!m_channelCapabilities.contains(channel))
{
return false;
}
const ChannelCapability &capability = m_channelCapabilities[channel];
// 检查连接类型支持
if (!capability.supportedConnections.contains(connection))
{
return false;
}
// 检查操作类型支持
if (operation != NONE && !capability.supportedOperations.contains(operation))
{
return false;
}
// 检查操作类型与通道类型的匹配
if (isInputChannelOperation(operation))
{
return capability.type == INPUT_CHANNEL;
}
else if (isOutputChannelOperation(operation))
{
return capability.type == OUTPUT_CHANNEL;
}
else if (operation == NONE)
{
return true;
}
return false;
}
bool ChannelManager::occupyChannel(ChannelId channel, OperationType operation,
const QString &description,
ConnectionType connectionType)
{
if (!isChannelAvailable(channel))
{
return false;
}
if (!canChannelSupport(channel, operation, connectionType))
{
return false;
}
ChannelStatus &status = m_channelStatus[channel];
status.occupied = true;
status.operationDetails.operation = operation;
status.operationDetails.description = description;
status.operationDetails.connectionType = connectionType;
status.occupiedTime = QDateTime::currentDateTime();
emit channelStatusChanged(channel, operation, description);
return true;
}
void ChannelManager::releaseChannel(ChannelId channel)
{
if (m_channelStatus.contains(channel))
{
ChannelStatus &status = m_channelStatus[channel];
status.occupied = false;
status.operationDetails.operation = NONE;
status.operationDetails.description.clear();
status.operationDetails.connectionType = TWO_WIRE;
status.occupiedTime = QDateTime();
emit channelReleased(channel);
emit channelStatusChanged(channel, NONE, QString());
}
}
ChannelManager::OperationType ChannelManager::getChannelOperation(ChannelId channel) const
{
return m_channelStatus.value(channel).operationDetails.operation;
}
QString ChannelManager::getChannelDescription(ChannelId channel) const
{
return m_channelStatus.value(channel).operationDetails.description;
}
ChannelManager::OperationDetails
ChannelManager::getChannelOperationDetails(ChannelId channel) const
{
return m_channelStatus.value(channel).operationDetails;
}
QList<ChannelManager::OperationType>
ChannelManager::getSupportedOperations(ChannelId channel) const
{
return m_channelCapabilities.value(channel).supportedOperations;
}
ChannelManager::ChannelCapability
ChannelManager::getChannelCapability(ChannelId channel) const
{
return m_channelCapabilities.value(channel);
}
QList<ChannelManager::ChannelId>
ChannelManager::getAvailableChannels(ChannelType type) const
{
QList<ChannelId> availableChannels;
for (auto it = m_channelCapabilities.constBegin();
it != m_channelCapabilities.constEnd(); ++it)
{
if (it.value().type == type && isChannelAvailable(it.key()))
{
availableChannels.append(it.key());
}
}
return availableChannels;
}
QString ChannelManager::getOperationDisplayName(OperationType operation) const
{
switch (operation)
{
case NONE:
return "空闲";
// 输入通道操作
case VOLTAGE_MEASUREMENT:
return "电压测量";
case MV_MEASUREMENT:
return "mV测量";
case MA_MEASUREMENT:
return "mA测量";
case AC_MEASUREMENT:
return "交流测量";
case RESISTANCE_MEASUREMENT:
return "电阻测量";
case FREQUENCY_MEASUREMENT:
return "频率测量";
case SWITCH_MEASUREMENT:
return "开关量测量";
case INSULATION_MEASUREMENT:
return "绝缘电阻测量";
// 输出通道操作
case VOLTAGE_OUTPUT:
return "电压输出";
case MV_OUTPUT:
return "mV输出";
case MA_OUTPUT:
return "mA输出";
case WAVEFORM_OUTPUT:
return "波形输出";
case RESISTANCE_SIMULATION:
return "电阻模拟";
}
return "未知";
}
QString ChannelManager::getConnectionTypeDisplayName(ConnectionType connection) const
{
switch (connection)
{
case TWO_WIRE:
return "二线制";
case THREE_WIRE:
return "三线制";
case FOUR_WIRE:
return "四线制";
}
return "未知";
}
QString ChannelManager::getDetailedOperationDescription(
const OperationDetails &details) const
{
QString baseDescription = getOperationDisplayName(details.operation);
if (details.operation == RESISTANCE_MEASUREMENT ||
details.operation == RESISTANCE_SIMULATION)
{
baseDescription +=
QString("(%1)").arg(getConnectionTypeDisplayName(details.connectionType));
}
if (!details.description.isEmpty())
{
baseDescription += QString(" - %1").arg(details.description);
}
return baseDescription;
}
bool ChannelManager::isInputChannelOperation(OperationType operation) const
{
switch (operation)
{
case VOLTAGE_MEASUREMENT:
case MV_MEASUREMENT:
case MA_MEASUREMENT:
case AC_MEASUREMENT:
case RESISTANCE_MEASUREMENT:
case FREQUENCY_MEASUREMENT:
case SWITCH_MEASUREMENT:
case INSULATION_MEASUREMENT:
return true;
default:
return false;
}
}
bool ChannelManager::isOutputChannelOperation(OperationType operation) const
{
switch (operation)
{
case VOLTAGE_OUTPUT:
case MV_OUTPUT:
case MA_OUTPUT:
case WAVEFORM_OUTPUT:
case RESISTANCE_SIMULATION:
return true;
default:
return false;
}
}
QString ChannelManager::getChannelDisplayName(ChannelId channel) const
{
switch (channel)
{
case INPUT_CHANNEL_1:
return "输入通道1";
case INPUT_CHANNEL_2:
return "输入通道2";
case OUTPUT_CHANNEL_1:
return "输出通道1";
case OUTPUT_CHANNEL_2:
return "输出通道2";
}
return "未知通道";
}
QList<ChannelManager::ChannelId>
ChannelManager::getChannelsWithOperation(OperationType operation) const
{
QList<ChannelId> channels;
for (auto it = m_channelStatus.constBegin(); it != m_channelStatus.constEnd(); ++it)
{
if (it.value().operationDetails.operation == operation)
{
channels.append(it.key());
}
}
return channels;
}

137
hardware/channelmanager.h Normal file
View File

@@ -0,0 +1,137 @@
#ifndef CHANNELMANAGER_H
#define CHANNELMANAGER_H
#include <QDateTime>
#include <QList>
#include <QMap>
#include <QObject>
/**
* @brief 通道管理器
*
* 管理校验仪的输入/输出通道状态
* - 输入通道1: 4线制支持所有测量功能
* - 输入通道2: 2线制支持基本测量
* - 输出通道1/2: 2线制支持电压/电流/波形输出
*/
class ChannelManager : public QObject
{
Q_OBJECT
public:
enum ChannelType
{
INPUT_CHANNEL,
OUTPUT_CHANNEL
};
enum ChannelId
{
INPUT_CHANNEL_1 = 1,
INPUT_CHANNEL_2 = 2,
OUTPUT_CHANNEL_1 = 3,
OUTPUT_CHANNEL_2 = 4
};
enum OperationType
{
// 通用状态
NONE,
// 输入通道操作状态
VOLTAGE_MEASUREMENT, // 电压测量
MV_MEASUREMENT, // mV测量
MA_MEASUREMENT, // mA测量
AC_MEASUREMENT, // 交流测量
RESISTANCE_MEASUREMENT, // 电阻测量(含热电阻及多线制)
FREQUENCY_MEASUREMENT, // 频率测量
SWITCH_MEASUREMENT, // 开关量测量
INSULATION_MEASUREMENT, // 绝缘电阻测量
// 输出通道操作状态
VOLTAGE_OUTPUT, // 电压输出
MV_OUTPUT, // mV输出
MA_OUTPUT, // mA输出
WAVEFORM_OUTPUT, // 波形输出
RESISTANCE_SIMULATION // 电阻模拟(含热电阻及多线制)
};
enum ConnectionType
{
TWO_WIRE,
THREE_WIRE,
FOUR_WIRE
};
struct ChannelCapability
{
ChannelType type;
int maxWires;
QStringList wireColors;
QList<ConnectionType> supportedConnections;
QList<OperationType> supportedOperations;
};
struct OperationDetails
{
OperationType operation;
QString description;
ConnectionType connectionType;
};
static ChannelManager *instance();
// 通道状态查询
bool isChannelAvailable(ChannelId channel) const;
bool canChannelSupport(ChannelId channel, OperationType operation,
ConnectionType connection = TWO_WIRE) const;
// 通道占用/释放
bool occupyChannel(ChannelId channel, OperationType operation,
const QString &description = QString(),
ConnectionType connectionType = TWO_WIRE);
void releaseChannel(ChannelId channel);
// 通道信息获取
OperationType getChannelOperation(ChannelId channel) const;
QString getChannelDescription(ChannelId channel) const;
OperationDetails getChannelOperationDetails(ChannelId channel) const;
ChannelCapability getChannelCapability(ChannelId channel) const;
QList<ChannelId> getAvailableChannels(ChannelType type) const;
QList<OperationType> getSupportedOperations(ChannelId channel) const;
// 显示名称
QString getOperationDisplayName(OperationType operation) const;
QString getConnectionTypeDisplayName(ConnectionType connection) const;
QString getDetailedOperationDescription(const OperationDetails &details) const;
QString getChannelDisplayName(ChannelId channel) const;
// 类型判断
bool isInputChannelOperation(OperationType operation) const;
bool isOutputChannelOperation(OperationType operation) const;
// 查询
QList<ChannelId> getChannelsWithOperation(OperationType operation) const;
signals:
void channelStatusChanged(ChannelId channel, OperationType operation,
const QString &description);
void channelReleased(ChannelId channel);
private:
explicit ChannelManager(QObject *parent = nullptr);
void initializeChannelCapabilities();
struct ChannelStatus
{
bool occupied;
OperationDetails operationDetails;
QDateTime occupiedTime;
};
QMap<ChannelId, ChannelStatus> m_channelStatus;
QMap<ChannelId, ChannelCapability> m_channelCapabilities;
static ChannelManager *m_instance;
};
#endif // CHANNELMANAGER_H