TestService.h 5.1 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 "report.h"
  16. #include"Msgbox.h"
  17. #include"serialui.h"
  18. #include <QSignalSpy>
  19. //#define MAX_COMPARTMENT_NUM (4)
  20. #define AVERAGE_PRESSURE_COUNT (2) //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 start_voltage;
  52. float 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_ROUGH_0=0, //粗调阀
  64. Valve_ID_ROUGH_1, //
  65. Valve_ID_ROUGH_2,
  66. Valve_ID_CALIBRATION, //压力校准阀
  67. Valve_ID_PRESSURESENSOR, //压力传感阀
  68. Valve_ID_VACUUM, //真空阀
  69. Valve_ID_VENT, //泄气阀
  70. Valve_ID_INTAKE, //进气阀
  71. Valve_ID_8,
  72. Valve_ID_9,
  73. Valve_ID_10,
  74. Valve_ID_11,
  75. Valve_ID_12,
  76. Valve_ID_13,
  77. Valve_ID_14,
  78. Valve_ID_15,
  79. Valve_ID_All,
  80. };
  81. Q_INVOKABLE void init();
  82. Q_INVOKABLE bool setTankinfo(const QVariantList& list);
  83. Q_INVOKABLE void valve_open(Valve_ID id);
  84. Q_INVOKABLE void valve_close(Valve_ID id);
  85. Q_INVOKABLE QString read_PressureValue();
  86. Q_INVOKABLE void adjust_Pressure(QString voltage_str);
  87. Q_INVOKABLE bool tstart(int compartmentid, int direction); //direction : 0 positive test , 1 negative test
  88. Q_INVOKABLE bool tselfstart(int compartmentid, int direction); //direction : 0 positive test , 1 negative test
  89. Q_INVOKABLE bool tstop(int compartmentid);
  90. Q_INVOKABLE bool reportpic_Ready(int compartmentid);
  91. Q_INVOKABLE bool check_alltest_ok();
  92. Q_INVOKABLE bool genReport(QString word_path, QString pic_dir);
  93. Q_INVOKABLE QJsonObject get_vrs_items();
  94. Q_INVOKABLE QJsonObject get_bls_items();
  95. Q_INVOKABLE bool set_item_result(const QString& jsonStr );
  96. signals:
  97. void sigPressure(int id, QVariantMap pressure_map);
  98. void sigState(int id, QString state_str1, QString state_str2);
  99. void sigSystemResult(int id, QString delta_str, bool bPassed);
  100. void sigValveResult(int id, QString delta_str, bool bPassed);
  101. void sigSelfTestResult(int id, QString delta_str, bool bPassed);
  102. void sigStop(int id);
  103. void onNotice(QString qstr);
  104. void onWarning(QString qstr);
  105. void onGenreportProgress(QString qstr);
  106. void operate();
  107. public slots:
  108. void receive_reportprogress(QString qstr);
  109. private:
  110. unsigned short Calcrc(const unsigned char *ptr, int count);
  111. void SendCmd(QSerialPort* pSerial, QByteArray data);
  112. bool check_crc(QByteArray data);
  113. bool Valve_op(Valve_ID id, Valve_OP op);
  114. bool Read_pressure(float & pressure);
  115. bool Adjust_pressure(unsigned short voltage);
  116. void push_pressurelist(float pressure);
  117. void clear_pressurelist();
  118. float calculate_averagepressure();
  119. bool OpenSerial3();
  120. bool OpenSerial4();
  121. // 0 ok
  122. // -1 timeout
  123. // -2 error
  124. Ret_Value Pressure_Adjust(const TestExpect& expect);
  125. // 0 ok
  126. // -1 timeout
  127. // -2 error
  128. Ret_Value Pressure_RoughAdjust(const TestExpect& expect);
  129. // 0 ok
  130. // -1 timeout
  131. // -2 error
  132. Ret_Value Pressure_Relief(const TestExpect& expect);
  133. //0 pass
  134. //-1 nopass
  135. Ret_Value Pressure_Keep(int keeptime, float threshold, float& delta);
  136. int make_messagebox(Test_Direction direction, Test_Step step, Ret_Value ret_v);
  137. QSerialPort * m_SerialPort3;
  138. QSerialPort * m_SerialPort4;
  139. QMutex m_Serial3mutex;
  140. QMutex m_Serial4mutex;
  141. //QSignalSpy m_spy3
  142. SerialUi m_SerialUi3;
  143. SerialUi m_SerialUi4;
  144. QTimer * m_pTimer_1; //read pressure value
  145. QTimer* m_pTimer_2; // testing process
  146. //QThread m_Thread;
  147. int m_compartmentid;
  148. bool m_bRunning;
  149. Tanker m_tank;
  150. QString m_standardname;
  151. Report m_report;
  152. QList<float> m_pressurelist; //用来计算平均压力
  153. QMutex m_pressuremutex;
  154. Test_Stage m_stage;
  155. Test_Step m_step;
  156. Test_Direction m_direction;
  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