TestService.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef TESTSERVICE_H
  2. #define TESTSERVICE_H
  3. #include <QTimer>
  4. #include <QDateTime>
  5. #include <QtSerialPort/QSerialPort>
  6. #include <QObject>
  7. #include <QSemaphore>
  8. #include <QThread>
  9. #include <QString>
  10. #include <QVector>
  11. #include <QMutex>
  12. #include <QDebug>
  13. //#include"Standard.h"
  14. #include "tank.h"
  15. #include "report.h"
  16. #include"Msgbox.h"
  17. #include"serialui.h"
  18. #include <QSignalSpy>
  19. //#define MAX_COMPARTMENT_NUM (4)
  20. #define AVERAGE_PRESSURE_COUNT (1) //5个不代表5秒, 要看采样频率
  21. typedef enum _Ret_Value{
  22. Ret_Failed = -2,
  23. Ret_Timeout = -1,
  24. Ret_OK = 0,
  25. Ret_Exit = 1
  26. }Ret_Value;
  27. enum Valve_OP{
  28. Valve_OP_Open = 0,
  29. Valve_OP_Close,
  30. };
  31. enum Test_Step{
  32. Test_Step_Start,
  33. Test_Step_AddPressure,
  34. Test_Step_AdjustPressure,
  35. Test_Step_KeepPressure,
  36. Test_Step_reliefPressure,
  37. Test_Step_End,
  38. };
  39. enum Test_Stage{
  40. Test_Stage_SysTest,
  41. Test_Stage_ValveTest,
  42. Test_Step_UNKown,
  43. };
  44. enum Test_Direction{
  45. Test_Direction_Positive,
  46. Test_Direction_Negative,
  47. Test_Direction_Unkown,
  48. };
  49. class TestExpect{
  50. public:
  51. int volume;
  52. double target; //pressure value
  53. int timeout; // timeout (s)
  54. };
  55. class TestService: public QThread
  56. {
  57. Q_OBJECT
  58. Q_ENUMS(Valve_ID)
  59. public:
  60. TestService(QThread *parent = nullptr);
  61. ~TestService();
  62. enum Valve_ID {
  63. Valve_ID_INTAKE=0, //进气阀
  64. Valve_ID_VACUUM, //真空阀
  65. Valve_ID_VENT, //泄气阀
  66. Valve_ID_4,
  67. Valve_ID_All,
  68. };
  69. Q_INVOKABLE void init();
  70. Q_INVOKABLE bool setTankinfo(const QVariantList& list);
  71. Q_INVOKABLE bool valve_open(Valve_ID id);
  72. Q_INVOKABLE bool valve_close(Valve_ID id);
  73. Q_INVOKABLE QString read_PressureValue();
  74. Q_INVOKABLE bool pressure_zero();
  75. Q_INVOKABLE bool ballvalve_control(QString position_str);
  76. Q_INVOKABLE QJsonObject ballvalve_status();
  77. Q_INVOKABLE bool tstart(int compartmentid, int direction); //direction : 0 positive test , 1 negative test
  78. Q_INVOKABLE bool tselfstart(int compartmentid, int direction); //direction : 0 positive test , 1 negative test
  79. Q_INVOKABLE bool tstop(int compartmentid);
  80. Q_INVOKABLE bool reportpic_Ready(int compartmentid);
  81. Q_INVOKABLE bool check_alltest_ok();
  82. Q_INVOKABLE bool genReport(QString word_path, QString pic_dir);
  83. Q_INVOKABLE QJsonObject get_vrs_items();
  84. Q_INVOKABLE QJsonObject get_bls_items();
  85. Q_INVOKABLE bool set_item_result(const QString& jsonStr );
  86. signals:
  87. void sigPressure(int id, QVariantMap pressure_map);
  88. void sigState(int id, QString state_str1, QString state_str2);
  89. void sigSystemResult(int id, QString delta_str, bool bPassed);
  90. void sigValveResult(int id, QString delta_str, bool bPassed);
  91. void sigSelfTestResult(int id, QString delta_str, bool bPassed);
  92. void sigStop(int id);
  93. void onNotice(QString qstr);
  94. void onWarning(QString qstr);
  95. void onGenreportProgress(QString qstr);
  96. void operate();
  97. public slots:
  98. void receive_reportprogress(QString qstr);
  99. private:
  100. //bool Adjust_pressure(unsigned short voltage);
  101. void push_pressurelist(float pressure);
  102. void clear_pressurelist();
  103. float calculate_averagepressure();
  104. bool OpenSerial3();
  105. bool OpenSerial4();
  106. bool self_checking();
  107. bool test_init();
  108. // 0 ok
  109. // -1 timeout
  110. // -2 error
  111. Ret_Value PositivePressure_Add(const TestExpect& expect);
  112. // 0 ok
  113. // -1 timeout
  114. // -2 error
  115. Ret_Value PositivePressure_Add_V2(const TestExpect& expect);
  116. // 0 ok
  117. // -1 timeout
  118. // -2 error
  119. Ret_Value Pressure_Relief(const TestExpect& expect);
  120. Ret_Value Pressure_Relief();
  121. // 0 ok
  122. // -1 timeout
  123. // -2 error
  124. Ret_Value Pressure_Keep(int keeptime, float& start_value, float& end_value);
  125. int make_messagebox(Test_Direction direction, Test_Step step, Ret_Value ret_v);
  126. //QSerialPort * m_SerialPort3;
  127. //QSerialPort * m_SerialPort4;
  128. //QMutex m_Serial3mutex;
  129. //QMutex m_Serial4mutex;
  130. //QSignalSpy m_spy3
  131. SerialUi m_SerialUi3;
  132. SerialUi m_SerialUi4;
  133. QTimer * m_pTimer_1; //read pressure value
  134. QTimer* m_pTimer_2; // testing process
  135. //QThread m_Thread;
  136. int m_compartmentid;
  137. bool m_bRunning;
  138. Tanker m_tank;
  139. //QString m_standardname;
  140. Standard m_standard;
  141. Report m_report;
  142. QList<float> m_pressurelist; //用来计算平均压力
  143. QMutex m_pressuremutex;
  144. Test_Stage m_stage;
  145. Test_Step m_step;
  146. Test_Direction m_direction;
  147. MsgBox m_msgbox;
  148. protected:
  149. void run() override;
  150. public slots:
  151. private slots:
  152. void OnTimer1();
  153. void OnTimer2();
  154. };
  155. #endif // TESTSERVICE_H