123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- #ifndef TESTSERVICE_H
- #define TESTSERVICE_H
- #include <QTimer>
- #include <QDateTime>
- #include <QtSerialPort/QSerialPort>
- #include <QObject>
- #include <QSemaphore>
- #include <QThread>
- #include <QString>
- #include <QVector>
- #include <QMutex>
- #include <QDebug>
- //#include"Standard.h"
- #include "tank.h"
- #include "report.h"
- #include"Msgbox.h"
- #include"serialui.h"
- #include <QSignalSpy>
- //#define MAX_COMPARTMENT_NUM (4)
- #define AVERAGE_PRESSURE_COUNT (2) //5个不代表5秒, 要看采样频率
- typedef enum _Ret_Value{
- Ret_Failed = -2,
- Ret_Timeout = -1,
- Ret_OK = 0,
- Ret_Exit = 1
- }Ret_Value;
- enum Valve_OP{
- Valve_OP_Open = 0,
- Valve_OP_Close,
- };
- enum Test_Step{
- Test_Step_Start,
- Test_Step_AddPressure,
- Test_Step_AdjustPressure,
- Test_Step_KeepPressure,
- Test_Step_reliefPressure,
- Test_Step_End,
- };
- enum Test_Stage{
- Test_Stage_SysTest,
- Test_Stage_ValveTest,
- Test_Step_UNKown,
- };
- enum Test_Direction{
- Test_Direction_Positive,
- Test_Direction_Negative,
- Test_Direction_Unkown,
- };
- class TestExpect{
- public:
- int start_voltage;
- float target; //pressure value
- int timeout; // timeout (s)
- };
- class TestService: public QThread
- {
- Q_OBJECT
- Q_ENUMS(Valve_ID)
- public:
- TestService(QThread *parent = nullptr);
- ~TestService();
- enum Valve_ID {
- Valve_ID_ROUGH_0=0, //粗调阀
- Valve_ID_ROUGH_1, //
- Valve_ID_ROUGH_2,
- Valve_ID_CALIBRATION, //压力校准阀
- Valve_ID_PRESSURESENSOR, //压力传感阀
- Valve_ID_VACUUM, //真空阀
- Valve_ID_VENT, //泄气阀
- Valve_ID_INTAKE, //进气阀
- Valve_ID_8,
- Valve_ID_9,
- Valve_ID_10,
- Valve_ID_11,
- Valve_ID_12,
- Valve_ID_13,
- Valve_ID_14,
- Valve_ID_15,
- Valve_ID_All,
- };
- Q_INVOKABLE void init();
- Q_INVOKABLE bool setTankinfo(const QVariantList& list);
- Q_INVOKABLE void valve_open(Valve_ID id);
- Q_INVOKABLE void valve_close(Valve_ID id);
- Q_INVOKABLE QString read_PressureValue();
- Q_INVOKABLE void adjust_Pressure(QString voltage_str);
- Q_INVOKABLE bool tstart(int compartmentid, int direction); //direction : 0 positive test , 1 negative test
- Q_INVOKABLE bool tselfstart(int compartmentid, int direction); //direction : 0 positive test , 1 negative test
- Q_INVOKABLE bool tstop(int compartmentid);
- Q_INVOKABLE bool reportpic_Ready(int compartmentid);
- Q_INVOKABLE bool check_alltest_ok();
- Q_INVOKABLE bool genReport(QString word_path, QString pic_dir);
- Q_INVOKABLE QJsonObject get_vrs_items();
- Q_INVOKABLE QJsonObject get_bls_items();
- Q_INVOKABLE bool set_item_result(const QString& jsonStr );
- signals:
- void sigPressure(int id, QVariantMap pressure_map);
- void sigState(int id, QString state_str1, QString state_str2);
- void sigSystemResult(int id, QString delta_str, bool bPassed);
- void sigValveResult(int id, QString delta_str, bool bPassed);
- void sigSelfTestResult(int id, QString delta_str, bool bPassed);
- void sigStop(int id);
- void onNotice(QString qstr);
- void onWarning(QString qstr);
- void onGenreportProgress(QString qstr);
- void operate();
- public slots:
- void receive_reportprogress(QString qstr);
- private:
- unsigned short Calcrc(const unsigned char *ptr, int count);
- void SendCmd(QSerialPort* pSerial, QByteArray data);
- bool check_crc(QByteArray data);
- bool Valve_op(Valve_ID id, Valve_OP op);
- bool Read_pressure(float & pressure);
- bool Adjust_pressure(unsigned short voltage);
- void push_pressurelist(float pressure);
- void clear_pressurelist();
- float calculate_averagepressure();
- bool OpenSerial3();
- bool OpenSerial4();
- // 0 ok
- // -1 timeout
- // -2 error
- Ret_Value Pressure_Adjust(const TestExpect& expect);
- // 0 ok
- // -1 timeout
- // -2 error
- Ret_Value Pressure_RoughAdjust(const TestExpect& expect);
- // 0 ok
- // -1 timeout
- // -2 error
- Ret_Value Pressure_Relief(const TestExpect& expect);
- //0 pass
- //-1 nopass
- Ret_Value Pressure_Keep(int keeptime, float threshold, float& delta);
- int make_messagebox(Test_Direction direction, Test_Step step, Ret_Value ret_v);
- QSerialPort * m_SerialPort3;
- QSerialPort * m_SerialPort4;
- QMutex m_Serial3mutex;
- QMutex m_Serial4mutex;
- //QSignalSpy m_spy3
- SerialUi m_SerialUi3;
- SerialUi m_SerialUi4;
- QTimer * m_pTimer_1; //read pressure value
- QTimer* m_pTimer_2; // testing process
- //QThread m_Thread;
- int m_compartmentid;
- bool m_bRunning;
- Tanker m_tank;
- QString m_standardname;
- Report m_report;
- QList<float> m_pressurelist; //用来计算平均压力
- QMutex m_pressuremutex;
- Test_Stage m_stage;
- Test_Step m_step;
- Test_Direction m_direction;
- MsgBox m_msgbox;
- protected:
- void run() override;
- public slots:
- private slots:
- void OnTimer1();
- void OnTimer2();
- };
- #endif // TESTSERVICE_H
|