TestService.h 4.8 KB

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