first commit
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
#ifndef PRODUCTIONSERVICE_H
|
||||
#define PRODUCTIONSERVICE_H
|
||||
|
||||
#include "deviceservice.h"
|
||||
|
||||
#include "../models/workpiece.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QObject>
|
||||
|
||||
class QTimer;
|
||||
|
||||
class ProductionService : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum State
|
||||
{
|
||||
Idle,
|
||||
Preparing,
|
||||
WaitingDeviceReady,
|
||||
Loading,
|
||||
FrontChecking,
|
||||
BackChecking,
|
||||
Judging,
|
||||
Unloading,
|
||||
Paused,
|
||||
Error,
|
||||
Completed,
|
||||
TimeoutWarning,
|
||||
TimeoutPaused,
|
||||
RecoveryChecking,
|
||||
ManualConfirm,
|
||||
Retrying
|
||||
};
|
||||
Q_ENUM(State)
|
||||
|
||||
static ProductionService &instance();
|
||||
|
||||
State state() const;
|
||||
QString stateName() const;
|
||||
int orderId() const;
|
||||
Workpiece currentWorkpiece() const;
|
||||
|
||||
bool start(int orderId, QString *error = nullptr);
|
||||
bool pause(QString *error = nullptr);
|
||||
bool resume(QString *error = nullptr);
|
||||
bool stop(QString *error = nullptr);
|
||||
bool reset(QString *error = nullptr);
|
||||
bool recover(QString *error = nullptr);
|
||||
bool retry(QString *error = nullptr);
|
||||
bool markCurrentWorkpieceNg(QString *error = nullptr);
|
||||
bool restoreActiveRun(QString *error = nullptr);
|
||||
|
||||
signals:
|
||||
void stateChanged(ProductionService::State state, const QString &name);
|
||||
void currentWorkpieceChanged(int workpieceId, const QString &barcode);
|
||||
void productionFinished(int orderId);
|
||||
void productionError(const QString &error);
|
||||
void alarmRaised(const QString &code, const QString &message);
|
||||
void processElapsedChanged(const QString &processStep, int elapsedMs);
|
||||
void timeoutWarning(const QString &state, int elapsedMs, int timeoutMs);
|
||||
void timeoutRecoveryRequired(const QString &state, const QString &message);
|
||||
void recoveryCompleted(const QString &mode);
|
||||
|
||||
private slots:
|
||||
void tick();
|
||||
void onDeviceStatusChanged(const DeviceStatus &status);
|
||||
void onCommunicationError(const QString &error);
|
||||
|
||||
private:
|
||||
explicit ProductionService(QObject *parent = nullptr);
|
||||
ProductionService(const ProductionService &) = delete;
|
||||
ProductionService &operator=(const ProductionService &) = delete;
|
||||
|
||||
void setState(State state);
|
||||
bool claimNextWorkpiece(QString *error);
|
||||
bool updateCurrentProcessStep(const QString &processStep, QString *error,
|
||||
bool forceRestart = false);
|
||||
bool finishCurrentWorkpiece(const QString &state, const QString &processStep,
|
||||
QString *error);
|
||||
bool finishOrder(QString *error);
|
||||
void tickSimulation();
|
||||
void tickProduction();
|
||||
bool processProductionStep(State state, QString *error);
|
||||
bool recoverFromPlcStep(QString *error);
|
||||
bool ensureOrderRunning(QString *error);
|
||||
bool checkRecoverySafety(QString *error) const;
|
||||
bool mapPlcStepToState(State *state, QString *processStep) const;
|
||||
void startProcessTimer(const QString &processStep);
|
||||
void pauseProcessTimer();
|
||||
void resumeProcessTimer();
|
||||
void clearProcessTimer();
|
||||
int currentProcessElapsedMs() const;
|
||||
void emitProcessElapsed();
|
||||
void persistRecoveryAction(const QString &action, const QString &message);
|
||||
bool isTimedState(State state) const;
|
||||
QString stateNameForState(State state) const;
|
||||
QString processStepForState(State state) const;
|
||||
QString runStateForState(State state) const;
|
||||
State stateFromName(const QString &name) const;
|
||||
void persistAlarm(const QString &code, const QString &message);
|
||||
void persistDeviceStatus(const DeviceStatus &status);
|
||||
void fail(const QString &error);
|
||||
bool isActive() const;
|
||||
|
||||
QTimer *m_timer;
|
||||
QElapsedTimer m_stateTimer;
|
||||
QElapsedTimer m_processTimer;
|
||||
QElapsedTimer m_heartbeatTimer;
|
||||
State m_state;
|
||||
State m_timeoutState;
|
||||
int m_runId;
|
||||
int m_orderId;
|
||||
Workpiece m_currentWorkpiece;
|
||||
DeviceStatus m_deviceStatus;
|
||||
bool m_deviceStatusValid;
|
||||
int m_recoveryRetryCount;
|
||||
int m_processElapsedMs;
|
||||
QString m_currentProcessStep;
|
||||
QString m_lastError;
|
||||
};
|
||||
|
||||
#endif // PRODUCTIONSERVICE_H
|
||||
Reference in New Issue
Block a user