订单流程修改--QThread事件循环导致的逻辑修改
This commit is contained in:
+56
-17
@@ -3,7 +3,10 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
#include <functional>
|
||||
|
||||
struct DeviceStatus
|
||||
{
|
||||
@@ -26,6 +29,12 @@ class DeviceService : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using OperationCallback = std::function<void(bool, const QString &)>;
|
||||
using StatusCallback =
|
||||
std::function<void(bool, const DeviceStatus &, const QString &)>;
|
||||
using ActionCallback =
|
||||
std::function<void(bool, bool, const QString &)>;
|
||||
|
||||
enum ProductionAction
|
||||
{
|
||||
RackPick,
|
||||
@@ -38,38 +47,68 @@ public:
|
||||
RackPlace
|
||||
};
|
||||
|
||||
static DeviceService &instance();
|
||||
explicit DeviceService(QObject *parent = nullptr);
|
||||
|
||||
void startPolling();
|
||||
void stopPolling();
|
||||
bool isPolling() const;
|
||||
|
||||
bool readStatus(DeviceStatus *status, QString *error = nullptr);
|
||||
bool start(QString *error = nullptr);
|
||||
bool pause(QString *error = nullptr);
|
||||
bool reset(QString *error = nullptr);
|
||||
bool clearAlarm(QString *error = nullptr);
|
||||
bool setInspectionMode(const QString &mode, QString *error = nullptr);
|
||||
bool executeProductionAction(ProductionAction action, int trayNo,
|
||||
int slotNo, QString *error = nullptr);
|
||||
void requestStatus(const StatusCallback &callback);
|
||||
void start(const OperationCallback &callback);
|
||||
void pause(const OperationCallback &callback);
|
||||
void reset(const OperationCallback &callback);
|
||||
void clearAlarm(const OperationCallback &callback);
|
||||
void setInspectionMode(const QString &mode,
|
||||
const OperationCallback &callback);
|
||||
void terminate(const OperationCallback &callback);
|
||||
void beginProductionAction(ProductionAction action, int trayNo,
|
||||
int slotNo, const OperationCallback &callback);
|
||||
void pollProductionAction(const ActionCallback &callback);
|
||||
void cancelProductionAction(const OperationCallback &callback);
|
||||
bool productionActionActive() const;
|
||||
bool productionActionBusy() const;
|
||||
|
||||
signals:
|
||||
void statusChanged(const DeviceStatus &status);
|
||||
void communicationError(const QString &error);
|
||||
|
||||
private:
|
||||
explicit DeviceService(QObject *parent = nullptr);
|
||||
DeviceService(const DeviceService &) = delete;
|
||||
DeviceService &operator=(const DeviceService &) = delete;
|
||||
|
||||
void pollStatus();
|
||||
DeviceStatus simulatedStatus() const;
|
||||
bool connectWithRetry(QString *error);
|
||||
bool readStatusOnce(DeviceStatus *status, QString *error);
|
||||
bool executeCommand(int commandAddress, int feedbackAddress, QString *error);
|
||||
bool waitForFeedback(int address, QString *error);
|
||||
void readStatusStep(int index, const DeviceStatus &status);
|
||||
void finishStatusRequest(bool success, const DeviceStatus &status,
|
||||
const QString &error);
|
||||
void executeCommand(int commandAddress, int feedbackAddress,
|
||||
const OperationCallback &callback,
|
||||
bool allowDuringTermination = false);
|
||||
void writeCommandAndWaitFeedback(int commandAddress, int feedbackAddress,
|
||||
const OperationCallback &callback,
|
||||
bool allowDuringTermination = false);
|
||||
void pollFeedback(int commandAddress, int feedbackAddress,
|
||||
const OperationCallback &callback,
|
||||
bool allowDuringTermination = false);
|
||||
void clearSignals(int commandAddress, int feedbackAddress,
|
||||
const OperationCallback &callback);
|
||||
void clearActionSignals(const OperationCallback &callback);
|
||||
void clearNextTerminationSignal();
|
||||
void finishTermination(bool success, const QString &error);
|
||||
void finishActionPoll(bool completed, const ActionCallback &callback);
|
||||
|
||||
QTimer *m_pollTimer;
|
||||
class ModbusTcpManager *m_modbus;
|
||||
bool m_statusRequestPending;
|
||||
QList<StatusCallback> m_statusCallbacks;
|
||||
bool m_controlRequestPending;
|
||||
bool m_productionActionActive;
|
||||
bool m_productionActionBusy;
|
||||
int m_productionCommandAddress;
|
||||
int m_productionFeedbackAddress;
|
||||
bool m_terminationActive;
|
||||
QList<QPair<int, int>> m_terminationSignals;
|
||||
int m_terminationSignalIndex;
|
||||
OperationCallback m_terminationCallback;
|
||||
int m_controlCommandAddress;
|
||||
int m_controlFeedbackAddress;
|
||||
};
|
||||
|
||||
#endif // DEVICESERVICE_H
|
||||
|
||||
Reference in New Issue
Block a user