TestService.h 5.2 KB

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