Files
ssp/services/productionworker.cpp
T
lidg 4046471c1a feat(production): 持久化动作检查点并完善恢复重试流程
- production_runs 新增动作阶段、尝试次数、版本及人工确认字段
- 提供兼容 PostgreSQL 9.5 的幂等升级脚本和数据库结构检查
- 工序推进、动作完成检查点和审计记录使用同一事务
- 机器人命令单次发送,完成反馈先持久化再清握手
- 已完成动作恢复仅补握手或数据库记录,避免重复执行
- 恢复/重试按钮固定显示在清除报警前,加入明确人工处理选项
- 记录人工决定、操作人及现场核对信息,拒绝过期确认
- 区分普通暂停继续、故障恢复与终止后的视觉锁解除
- 补齐视觉目标跨重启校验、异步失败及迟到回调防护
- 检测结果关联动作和尝试次数,重试清除旧结果缓存
2026-10-29 21:12:15 +08:00

159 lines
4.9 KiB
C++

#include "productionworker.h"
ProductionWorker::ProductionWorker(QObject *parent)
: QObject(parent)
, m_service(nullptr)
, m_stopRequested(false)
{
}
void ProductionWorker::ensureService()
{
if (m_service) {
return;
}
m_service = new ProductionService(this);
m_service->setExternalStopFlag(&m_stopRequested);
connect(m_service, &ProductionService::visionMeasureRequested, this, &ProductionWorker::visionMeasureRequested);
connect(m_service, &ProductionService::visionCancelRequested, this, &ProductionWorker::visionCancelRequested);
connect(m_service, &ProductionService::visionCycleChanged, this, &ProductionWorker::visionCycleChanged);
connect(m_service, &ProductionService::visionProductionActiveChanged, this, &ProductionWorker::visionProductionActiveChanged);
connect(m_service, &ProductionService::stateChanged,
this, &ProductionWorker::stateChanged);
connect(m_service, &ProductionService::deviceStatusChanged,
this, &ProductionWorker::deviceStatusChanged);
connect(m_service, &ProductionService::deviceCommunicationError,
this, &ProductionWorker::deviceCommunicationError);
connect(m_service, &ProductionService::currentWorkpieceChanged,
this, &ProductionWorker::currentWorkpieceChanged);
connect(m_service, &ProductionService::currentWorkpieceSnapshotChanged,
this, &ProductionWorker::currentWorkpieceSnapshotChanged);
connect(m_service, &ProductionService::currentPositionChanged,
this, &ProductionWorker::currentPositionChanged);
connect(m_service, &ProductionService::productionFinished,
this, &ProductionWorker::productionFinished);
connect(m_service, &ProductionService::productionError,
this, &ProductionWorker::productionError);
connect(m_service, &ProductionService::alarmRaised,
this, &ProductionWorker::alarmRaised);
connect(m_service, &ProductionService::processElapsedChanged,
this, &ProductionWorker::processElapsedChanged);
connect(m_service, &ProductionService::timeoutWarning,
this, &ProductionWorker::timeoutWarning);
connect(m_service, &ProductionService::timeoutRecoveryRequired,
this, &ProductionWorker::timeoutRecoveryRequired);
connect(m_service, &ProductionService::recoveryCompleted,
this, &ProductionWorker::recoveryCompleted);
connect(m_service, &ProductionService::recoveryDecisionRequired,
this, &ProductionWorker::recoveryDecisionRequired);
connect(m_service, &ProductionService::recoveryBusyChanged,
this, &ProductionWorker::recoveryBusyChanged);
}
void ProductionWorker::requestStopImmediate()
{
m_stopRequested.store(true);
}
void ProductionWorker::updateVisionAvailability(bool ready, bool busy, const QString &session)
{
ensureService();
m_service->onVisionAvailability(ready, busy, session);
}
void ProductionWorker::receiveVisionResult(const QJsonObject &result)
{
ensureService();
m_service->onVisionResult(result);
}
void ProductionWorker::requestVisionSnapshot()
{
ensureService();
m_service->publishVisionSnapshot();
}
void ProductionWorker::reportFailure(bool success, const QString &error)
{
if (!success && !error.isEmpty()) {
emit productionError(error);
}
}
void ProductionWorker::requestStart(int orderId)
{
ensureService();
QString error;
reportFailure(m_service->start(orderId, &error), error);
}
void ProductionWorker::requestPause()
{
ensureService();
QString error;
reportFailure(m_service->pause(&error), error);
}
void ProductionWorker::requestResume()
{
ensureService();
QString error;
reportFailure(m_service->resume(&error), error);
}
void ProductionWorker::requestStop()
{
ensureService();
QString error;
reportFailure(m_service->stop(&error), error);
}
void ProductionWorker::requestClearAlarm()
{
ensureService();
QString error;
reportFailure(m_service->clearAlarm(&error), error);
}
void ProductionWorker::requestRecover()
{
ensureService();
QString error;
reportFailure(m_service->recover(&error), error);
}
void ProductionWorker::requestRecoveryDecision(const QJsonObject &decision)
{
ensureService();
QString error;
reportFailure(m_service->submitRecoveryDecision(decision, &error), error);
}
void ProductionWorker::requestMarkNg()
{
ensureService();
QString error;
reportFailure(m_service->markCurrentWorkpieceNg(&error), error);
}
void ProductionWorker::requestRestore()
{
ensureService();
QString error;
reportFailure(m_service->restoreActiveRun(&error), error);
}
void ProductionWorker::requestShutdown()
{
ensureService();
m_service->shutdown(
[this](bool success, const QString &error) {
if (!success) {
reportFailure(false, error);
return;
}
emit shutdownReady();
});
}